22 #include "UTF8Util.hpp" 
   28 inline size_t FNVHash(
const char* text, 
const size_t byteLength,
 
   29                       const size_t FNV_prime, 
const size_t FNV_offset_basis) {
 
   30   size_t hash = FNV_offset_basis;
 
   31   for (
const char* pstr = text; pstr < text + byteLength; pstr++) {
 
   38 template <
int> 
size_t FNVHash(
const char* text, 
const size_t byteLength);
 
   41 inline size_t FNVHash<4>(
const char* text, 
const size_t byteLength) {
 
   42   return FNVHash(text, byteLength, 16777619UL, 2166136261UL);
 
   45 #if SIZE_MAX == 0xffffffffffffffff 
   47 inline size_t FNVHash<8>(
const char* text, 
const size_t byteLength) {
 
   48   return FNVHash(text, byteLength, 1099511628211UL, 14695981039346656037UL);
 
   56   typedef LENGTH_TYPE LengthType;
 
   60         byteLength(
static_cast<LengthType
>(strlen(_str))) {}
 
   63       : str(_str), utf8Length(_utf8Length) {
 
   64     CalculateByteLength();
 
   68                       const LengthType _byteLength)
 
   69       : str(_str), utf8Length(_utf8Length), byteLength(_byteLength) {
 
   70     CalculateByteLength();
 
   73   LengthType UTF8Length()
 const { 
return utf8Length; }
 
   75   LengthType ByteLength()
 const { 
return byteLength; }
 
   78     if (numberOfCharacters == UTF8Length()) {
 
   86     if (numberOfCharacters == UTF8Length()) {
 
   89       const char* pstr = str + byteLength;
 
   90       for (
size_t i = 0; i < numberOfCharacters; i++) {
 
   98                                 const LengthType numberOfCharacters)
 const {
 
  100       return Left(numberOfCharacters);
 
  102       const char* pstr = str;
 
  103       for (
size_t i = 0; i < offset; i++) {
 
  110   std::string ToString()
 const { 
return std::string(str, str + byteLength); }
 
  112   const char* CString()
 const { 
return str; }
 
  115     if (str == that.str) {
 
  116       return (std::min)(utf8Length, that.utf8Length);
 
  118       const char* pstr1 = str;
 
  119       const char* pstr2 = that.str;
 
  120       for (
size_t length = 0; length < utf8Length && length < that.utf8Length;
 
  124         if (charLen1 != charLen2 || strncmp(pstr1, pstr2, charLen1) != 0) {
 
  135     if (utf8Length > 0) {
 
  139       byteLength -= charLen;
 
  144     if (utf8Length > 0) {
 
  147       byteLength -= charLen;
 
  152     const char* pstr1 = str + byteLength;
 
  153     const char* pstr2 = that.str + that.byteLength;
 
  154     const size_t length = (std::min)(utf8Length, that.utf8Length);
 
  155     for (
size_t i = 0; i < length; i++) {
 
  160       const int cmp = strncmp(pstr1, pstr2, (std::min)(charLen1, charLen2));
 
  163       } 
else if (cmp > 0) {
 
  165       } 
else if (charLen1 < charLen2) {
 
  167       } 
else if (charLen1 > charLen2) {
 
  171     if (utf8Length < that.utf8Length) {
 
  173     } 
else if (utf8Length > that.utf8Length) {
 
  181     return static_cast<LengthType
>(
 
  182         ToString().find(pattern.str, 0, pattern.byteLength));
 
  186     return Compare(that) < 0;
 
  190     return Compare(that) > 0;
 
  194     return (str == that.str && utf8Length == that.utf8Length) ||
 
  199     return !this->operator==(that);
 
  205       return internal::FNVHash<sizeof(size_t)>(text.CString(),
 
  212     int cmp = strncmp(str, that.str, (std::min)(byteLength, that.byteLength));
 
  214       if (utf8Length < that.utf8Length) {
 
  216       } 
else if (utf8Length > that.utf8Length) {
 
  225   void CalculateByteLength() {
 
  226     const char* pstr = str;
 
  227     for (
size_t i = 0; i < utf8Length; i++) {
 
  230     byteLength = 
static_cast<LengthType
>(pstr - str);
 
  234   LengthType utf8Length;
 
  235   LengthType byteLength;
 
  238 typedef UTF8StringSliceBase<size_t> UTF8StringSlice;
 
  240 template <
typename LENGTH_TYPE>
 
  241 std::ostream& operator<<(::std::ostream& os,
 
  242                          const UTF8StringSliceBase<LENGTH_TYPE>& str) {
 
  243   return os << str.ToString();