! * \brief Gets the index where a character begin * * Iterate through the string to find the starting position of a specific character index * This is useful because non-ASCII characters may be encoded using multiple bytes. * * \param characterIndex Index of the character to search for * * \return Starting index */
| 2105 | * \return Starting index |
| 2106 | */ |
| 2107 | std::size_t String::GetCharacterPosition(std::size_t characterIndex) const |
| 2108 | { |
| 2109 | const char* ptr = m_sharedString->string.get(); |
| 2110 | const char* end = &m_sharedString->string[m_sharedString->size]; |
| 2111 | |
| 2112 | try |
| 2113 | { |
| 2114 | utf8::advance(ptr, characterIndex, end); |
| 2115 | |
| 2116 | return ptr - m_sharedString->string.get(); |
| 2117 | } |
| 2118 | catch (utf8::not_enough_room& /*e*/) |
| 2119 | { |
| 2120 | // Returns npos |
| 2121 | } |
| 2122 | catch (utf8::exception& e) |
| 2123 | { |
| 2124 | NazaraError("UTF-8 error: " + String(e.what())); |
| 2125 | } |
| 2126 | catch (std::exception& e) |
| 2127 | { |
| 2128 | NazaraError(e.what()); |
| 2129 | } |
| 2130 | |
| 2131 | return npos; |
| 2132 | } |
| 2133 | |
| 2134 | /*! |
| 2135 | * \brief Gets the raw buffer |
no test coverage detected