Method: ConverterBase#insert_word_separator
- Defined in:
- lib/converterbase.rb
#insert_word_separator(str) ⇒ Object
単語単位でzwsを挿入する
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 |
# File 'lib/converterbase.rb', line 1212 def insert_word_separator(str) buffer = +"" ss = StringScanner.new(str) before_symbol = false if @text_type == "textfile" buffer << ss.scan(/(.+\n){2}/) end while char = ss.getch symbol = false case char when "|" ss.scan(/.+?》/) when "[" buffer << char if ss.scan(/^#.+?]/) buffer << "#{ss.matched}" else before_symbol = false end next when "<" if ss.scan(/.+?>/) buffer << "<#{ss.matched}" next end symbol = true when /[\d0-9]/ ss.scan(/[\d0-9]+/) when /[ぁ-んゝゞ]/ ss.scan(/[ぁ-んゝゞー]+/) when /[ァ-ヶ]/ ss.scan(/[ァ-ヶー・]+/) when /[A-Za-zA-Za-z]/ ss.scan(/[A-Za-zA-Za-z ]+/) when /[一-龥朗-鶴]/ ss.scan(/[一-龥朗-鶴]+/) when /[〔「『\((【〈《≪〝]/ buffer << char before_symbol = false next else symbol = true end if before_symbol && !symbol buffer << WORD_SEPARATOR end buffer << char unless symbol buffer << ss.matched if ss.matched? buffer << WORD_SEPARATOR end before_symbol = symbol end buffer end |