| 2294 | */ |
| 2295 | |
| 2296 | std::size_t String::GetWordPosition(unsigned int index, UInt32 flags) const |
| 2297 | { |
| 2298 | if (m_sharedString->size == 0) |
| 2299 | return npos; |
| 2300 | |
| 2301 | unsigned int currentWord = 0; |
| 2302 | bool inWord = false; |
| 2303 | |
| 2304 | const char* ptr = m_sharedString->string.get(); |
| 2305 | if (flags & HandleUtf8) |
| 2306 | { |
| 2307 | utf8::unchecked::iterator<const char*> it(ptr); |
| 2308 | do |
| 2309 | { |
| 2310 | if (Detail::IsSpace(*it)) |
| 2311 | inWord = false; |
| 2312 | else |
| 2313 | { |
| 2314 | if (!inWord) |
| 2315 | { |
| 2316 | inWord = true; |
| 2317 | if (++currentWord > index) |
| 2318 | return it.base() - m_sharedString->string.get(); |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | while (*++it); |
| 2323 | } |
| 2324 | else |
| 2325 | { |
| 2326 | do |
| 2327 | { |
| 2328 | if (Detail::IsSpace(*ptr)) |
| 2329 | inWord = false; |
| 2330 | else |
| 2331 | { |
| 2332 | if (!inWord) |
| 2333 | { |
| 2334 | inWord = true; |
| 2335 | if (++currentWord > index) |
| 2336 | return ptr - m_sharedString->string.get(); |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | while (*++ptr); |
| 2341 | } |
| 2342 | |
| 2343 | return npos; |
| 2344 | } |
| 2345 | |
| 2346 | /*! |
| 2347 | * \brief Inserts the character into the string |