#ifndef V8_STRINGS_UNICODE_INL_H_
#define V8_STRINGS_UNICODE_INL_H_
#include "src/base/logging.h"
#include "src/strings/unicode.h"
#include "src/utils/utils.h"
namespace unibrow {
#ifndef V8_INTL_SUPPORT
template <class T, int s>
bool Predicate<T, s>::get(uchar code_point) {
CacheEntry entry = entries_[code_point & kMask];
if (entry.code_point() == code_point) return entry.value();
return CalculateValue(code_point);
}
template <class T, int s>
bool Predicate<T, s>::CalculateValue(uchar code_point) {
bool result = T::Is(code_point);
entries_[code_point & kMask] = CacheEntry(code_point, result);
return result;
}
template <class T, int s>
int Mapping<T, s>::get(uchar c, uchar n, uchar* result) {
CacheEntry entry = entries_[c & kMask];
if (entry.code_point_ == c) {
if (entry.offset_ == 0) {
return 0;
} else {
result[0] = c + entry.offset_;
return 1;
}
} else {
return CalculateValue(c, n, result);
}
}
template <class T, int s>
int Mapping<T, s>::CalculateValue(uchar c, uchar n, uchar* result) {
bool allow_caching = true;
int length = T::Convert(c, n, result, &allow_caching);
if (allow_caching) {
if (length == 1) {
entries_[c & kMask] = CacheEntry(c, result[0] - c);
return 1;
} else {
entries_[c & kMask] = CacheEntry(c, 0);
return 0;
}
} else {
return length;
}
}
#endif
bool Utf16::HasUnpairedSurrogate(const uint16_t* code_units, size_t length) { … }
uchar Utf8::ValueOfIncremental(const uint8_t** cursor, State* state,
Utf8IncrementalBuffer* buffer) { … }
unsigned Utf8::EncodeOneByte(char* str, uint8_t c) { … }
unsigned Utf8::Encode(char* str, uchar c, int previous, bool replace_invalid) { … }
uchar Utf8::ValueOf(const uint8_t* bytes, size_t length, size_t* cursor) { … }
unsigned Utf8::Length(uchar c, int previous) { … }
bool Utf8::IsValidCharacter(uchar c) { … }
}
#endif