mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
This function is (indirectly) used by a lot of code, and not all of it provide with valid indexes, though it seems like an issue that can be fixed locally, hence why I have decided to allow it (coupled with this being the main reason for crashes). It is however still not allowed when building in debug mode (rationale being that running it in debug mode and getting an assertion failure should provide enough info to fix the issue).
41 lines
965 B
C++
41 lines
965 B
C++
#ifndef UTF16_H_VKRVH0HR
|
|
#define UTF16_H_VKRVH0HR
|
|
|
|
#include "utf8.h"
|
|
#include <oak/oak.h>
|
|
|
|
namespace utf16
|
|
{
|
|
template <typename _Iter>
|
|
_Iter advance (_Iter const& first, size_t distance)
|
|
{
|
|
utf8::iterator_t<char const*> it(first);
|
|
for(; distance; ++it)
|
|
distance -= (*it > 0xFFFF) ? 2 : 1;
|
|
return ⁢
|
|
}
|
|
|
|
template <typename _Iter>
|
|
_Iter advance (_Iter const& first, size_t distance, _Iter const& last)
|
|
{
|
|
ASSERT(last == utf8::find_safe_end(first, last));
|
|
utf8::iterator_t<char const*> it(first);
|
|
for(; distance && &it != last; ++it)
|
|
distance -= (*it > 0xFFFF) ? 2 : 1;
|
|
return ⁢
|
|
}
|
|
|
|
template <typename _Iter>
|
|
size_t distance (_Iter const& first, _Iter const& last)
|
|
{
|
|
ASSERT(last == utf8::find_safe_end(first, last));
|
|
size_t res = 0;
|
|
foreach(it, utf8::make(first), utf8::make(utf8::find_safe_end(first, last)))
|
|
res += (*it > 0xFFFF) ? 2 : 1;
|
|
return res;
|
|
}
|
|
|
|
} /* utf16 */
|
|
|
|
#endif /* end of include guard: UTF16_H_VKRVH0HR */
|