* Itemize the string into runs per script, based on the previous created runs. * * Basically, this always returns the same or more runs than given. * * @param buff The string to itemize. * @param length The length of the string. * @param runs_current The current runs. * @return The runs. */
| 300 | * @return The runs. |
| 301 | */ |
| 302 | std::vector<ICURun> ItemizeScript(UChar *buff, size_t length, std::vector<ICURun> &runs_current) |
| 303 | { |
| 304 | std::vector<ICURun> runs; |
| 305 | icu::ScriptRun script_itemizer(buff, length); |
| 306 | |
| 307 | int cur_pos = 0; |
| 308 | auto cur_run = runs_current.begin(); |
| 309 | while (true) { |
| 310 | while (cur_pos < script_itemizer.getScriptEnd() && cur_run != runs_current.end()) { |
| 311 | int stop_pos = std::min(script_itemizer.getScriptEnd(), cur_run->start + cur_run->length); |
| 312 | assert(stop_pos - cur_pos > 0); |
| 313 | |
| 314 | runs.emplace_back(cur_pos, stop_pos - cur_pos, cur_run->level, script_itemizer.getScriptCode()); |
| 315 | |
| 316 | if (stop_pos == cur_run->start + cur_run->length) cur_run++; |
| 317 | cur_pos = stop_pos; |
| 318 | } |
| 319 | |
| 320 | if (!script_itemizer.next()) break; |
| 321 | } |
| 322 | |
| 323 | return runs; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Itemize the string into runs per style, based on the previous created runs. |
no test coverage detected