Update the dictionary and the transforms.

This commit is contained in:
Zoltan Szabadka 2014-03-25 16:48:25 +01:00
parent e7650080a8
commit 347781947a
9 changed files with 22402 additions and 11441 deletions

File diff suppressed because it is too large Load Diff

View File

@ -987,7 +987,8 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
copy_dst = &ringbuffer[pos & ringbuffer_mask];
if (distance > max_distance) {
if (copy_length >= 3 && copy_length <= kMaxDictionaryWordLength) {
if (copy_length >= kMinDictionaryWordLength &&
copy_length <= kMaxDictionaryWordLength) {
int offset = kBrotliDictionaryOffsetsByLength[copy_length];
int word_id = distance - max_distance - 1;
int shift = kBrotliDictionarySizeBitsByLength[copy_length];

File diff suppressed because it is too large Load Diff

View File

@ -28,17 +28,26 @@ extern "C" {
enum WordTransformType {
kIdentity = 0,
kOmit1 = 1,
kOmit2 = 2,
kOmit3 = 3,
kOmit4 = 4,
kOmit5 = 5,
kOmit6 = 6,
kOmit7 = 7,
kOmit8 = 8,
kOmit9 = 9,
kOmitLast1 = 1,
kOmitLast2 = 2,
kOmitLast3 = 3,
kOmitLast4 = 4,
kOmitLast5 = 5,
kOmitLast6 = 6,
kOmitLast7 = 7,
kOmitLast8 = 8,
kOmitLast9 = 9,
kUppercaseFirst = 10,
kUppercaseAll = 11
kUppercaseAll = 11,
kOmitFirst1 = 12,
kOmitFirst2 = 13,
kOmitFirst3 = 14,
kOmitFirst4 = 15,
kOmitFirst5 = 16,
kOmitFirst6 = 17,
kOmitFirst7 = 18,
kOmitFirst8 = 19,
kOmitFirst9 = 20
};
typedef struct {
@ -48,105 +57,127 @@ typedef struct {
} Transform;
static const Transform kTransforms[] = {
{ "", kIdentity, "" },
{ "", kIdentity, " ", },
{ "", kIdentity, "\">" },
{ "", kUppercaseFirst, "" },
{ "", kIdentity, "\"" },
{ "", kIdentity, ".", },
{ "", kIdentity, "=\"" },
{ "", kUppercaseFirst, " ", },
{ " ", kIdentity, "=\"" },
{ " ", kIdentity, " ", },
{ "", kIdentity, ":", },
{ " ", kIdentity, "" },
{ "", kIdentity, "\n" },
{ "", kIdentity, "(", },
{ "", kUppercaseAll, "" },
{ ".", kIdentity, "(", },
{ "", kIdentity, "'" },
{ "", kUppercaseFirst, "\"" },
{ " ", kUppercaseFirst, " ", },
{ "", kOmit3, "" },
{ "", kOmit4, "" },
{ ".", kIdentity, "" },
{ "", kOmit1, "" },
{ "", kOmit2, "" },
{ "", kUppercaseFirst, "\">" },
{ "", kOmit5, "" },
{ "", kUppercaseAll, " ", },
{ " ", kUppercaseFirst, "" },
{ "", kIdentity, ", ", },
{ "", kUppercaseFirst, "(", },
{ "", kIdentity, "\n\t" },
{ "", kUppercaseFirst, "'" },
{ ".", kIdentity, " ", },
{ " ", kUppercaseAll, " ", },
{ "", kIdentity, "='" },
{ "", kUppercaseFirst, ".", },
{ " ", kIdentity, ".", },
{ " ", kIdentity, ", ", },
{ " ", kUppercaseAll, "" },
{ "", kOmit6, "" },
{ "", kOmit9, "" },
{ "", kUppercaseAll, "\"" },
{ "", kIdentity, " the " },
{ "", kIdentity, " in " },
{ "", kIdentity, " of " },
{ "", kIdentity, " to " },
{ "", kIdentity, " and " },
{ "", kIdentity, " is " },
{ "", kIdentity, " on " },
{ "", kIdentity, " by " },
{ "", kIdentity, " for " },
{ "", kIdentity, " with " },
{ "", kIdentity, " from " },
{ "", kIdentity, " as " },
{ "", kIdentity, " at " },
{ "", kIdentity, "er " },
{ " ", kIdentity, "='" },
{ "", kIdentity, " a " },
{ "", kOmit7, "" },
{ "", kOmit8, "" },
{ " ", kIdentity, "(", },
{ " ", kIdentity, ". ", },
{ "", kIdentity, ". ", },
{ "", kIdentity, ",", },
{ "", kOmit1, "ing " },
{ "", kIdentity, "ed " },
{ "", kUppercaseFirst, ", ", },
{ "", kUppercaseAll, ".", },
{ "", kUppercaseAll, "=\"" },
{ "", kUppercaseAll, ", ", },
{ "", kUppercaseAll, "\">" },
{ " ", kUppercaseFirst, ".", },
{ " ", kUppercaseAll, "=\"" },
{ " ", kUppercaseFirst, ", ", },
{ "", kUppercaseAll, "'" },
{ "", kUppercaseFirst, "=\"" },
{ " ", kIdentity, ",", },
{ "", kIdentity, " that " },
{ "", kUppercaseFirst, "='" },
{ "", kUppercaseFirst, ". ", },
{ "", kUppercaseFirst, ",", },
{ "", kIdentity, ". The " },
{ "\xc2\xa0", kIdentity, "" },
{ " ", kUppercaseFirst, ". ", },
{ "", kUppercaseAll, ",", },
{ "", kUppercaseAll, "(", },
{ " ", kUppercaseAll, "='" },
{ "", kIdentity, "]" },
{ "", kUppercaseAll, "='" },
{ " ", kUppercaseAll, ".", },
{ "", kUppercaseAll, ". ", },
{ " ", kUppercaseFirst, "=\"" },
{ " ", kUppercaseAll, ". ", },
{ " ", kUppercaseFirst, ",", },
{ " ", kUppercaseAll, ", ", },
{ "", kIdentity, "ize " },
{ " ", kUppercaseFirst, "='" },
{ "", kIdentity, "est " },
{ "", kIdentity, ". This " },
{ "", kIdentity, "" },
{ "", kIdentity, " " },
{ " ", kIdentity, " " },
{ "", kOmitFirst1, "" },
{ "", kUppercaseFirst, " " },
{ "", kIdentity, " the " },
{ " ", kIdentity, "" },
{ "s ", kIdentity, " " },
{ "", kIdentity, " of " },
{ "", kUppercaseFirst, "" },
{ "", kIdentity, " and " },
{ "", kOmitFirst2, "" },
{ "", kOmitLast1, "" },
{ ", ", kIdentity, " " },
{ "", kIdentity, ", " },
{ " ", kUppercaseFirst, " " },
{ "", kIdentity, " in " },
{ "", kIdentity, " to " },
{ "e ", kIdentity, " " },
{ "", kIdentity, "\"" },
{ "", kIdentity, "." },
{ "", kIdentity, "\">" },
{ "", kIdentity, "\n" },
{ "", kOmitLast3, "" },
{ "", kIdentity, "]" },
{ "", kIdentity, " for " },
{ "", kOmitFirst3, "" },
{ "", kOmitLast2, "" },
{ "", kIdentity, " a " },
{ "", kIdentity, " that " },
{ " ", kUppercaseFirst, "" },
{ "", kIdentity, ". " },
{ ".", kIdentity, "" },
{ " ", kIdentity, ", " },
{ "", kOmitFirst4, "" },
{ "", kIdentity, " with " },
{ "", kIdentity, "'" },
{ "", kIdentity, " from " },
{ "", kIdentity, " by " },
{ "", kOmitFirst5, "" },
{ "", kOmitFirst6, "" },
{ " the ", kIdentity, "" },
{ "", kOmitLast4, "" },
{ "", kIdentity, ". The " },
{ "", kUppercaseAll, "" },
{ "", kIdentity, " on " },
{ "", kIdentity, " as " },
{ "", kIdentity, " is " },
{ "", kOmitLast7, "" },
{ "", kOmitLast1, "ing " },
{ "", kIdentity, "\n\t" },
{ "", kIdentity, ":" },
{ " ", kIdentity, ". " },
{ "", kIdentity, "ed " },
{ "", kOmitFirst9, "" },
{ "", kOmitFirst7, "" },
{ "", kOmitLast6, "" },
{ "", kIdentity, "(" },
{ "", kUppercaseFirst, ", " },
{ "", kOmitLast8, "" },
{ "", kIdentity, " at " },
{ "", kIdentity, "ly " },
{ " the ", kIdentity, " of " },
{ "", kOmitLast5, "" },
{ "", kOmitLast9, "" },
{ " ", kUppercaseFirst, ", " },
{ "", kUppercaseFirst, "\"" },
{ ".", kIdentity, "(" },
{ "", kUppercaseAll, " " },
{ "", kUppercaseFirst, "\">" },
{ "", kIdentity, "=\"" },
{ " ", kIdentity, "." },
{ ".com/", kIdentity, "" },
{ " the ", kIdentity, " of the " },
{ "", kUppercaseFirst, "'" },
{ "", kIdentity, ". This " },
{ "", kIdentity, "," },
{ ".", kIdentity, " " },
{ "", kUppercaseFirst, "(" },
{ "", kUppercaseFirst, "." },
{ "", kIdentity, " not " },
{ " ", kIdentity, "=\"" },
{ "", kIdentity, "er " },
{ " ", kUppercaseAll, " " },
{ "", kIdentity, "al " },
{ " ", kUppercaseAll, "" },
{ "", kIdentity, "='" },
{ "", kUppercaseAll, "\"" },
{ "", kUppercaseFirst, ". " },
{ " ", kIdentity, "(" },
{ "", kIdentity, "ful " },
{ " ", kUppercaseFirst, ". " },
{ "", kIdentity, "ive " },
{ "", kIdentity, "less " },
{ "", kUppercaseAll, "'" },
{ "", kIdentity, "est " },
{ " ", kUppercaseFirst, "." },
{ "", kUppercaseAll, "\">" },
{ " ", kIdentity, "='" },
{ "", kUppercaseFirst, "," },
{ "", kIdentity, "ize " },
{ "", kUppercaseAll, "." },
{ "\xc2\xa0", kIdentity, "" },
{ " ", kIdentity, "," },
{ "", kUppercaseFirst, "=\"" },
{ "", kUppercaseAll, "=\"" },
{ "", kIdentity, "ous " },
{ "", kUppercaseAll, ", " },
{ "", kUppercaseFirst, "='" },
{ " ", kUppercaseFirst, "," },
{ " ", kUppercaseAll, "=\"" },
{ " ", kUppercaseAll, ", " },
{ "", kUppercaseAll, "," },
{ "", kUppercaseAll, "(" },
{ "", kUppercaseAll, ". " },
{ " ", kUppercaseAll, "." },
{ "", kUppercaseAll, "='" },
{ " ", kUppercaseAll, ". " },
{ " ", kUppercaseFirst, "=\"" },
{ " ", kUppercaseAll, "='" },
{ " ", kUppercaseFirst, "='" },
};
static const int kNumTransforms = sizeof(kTransforms) / sizeof(kTransforms[0]);
@ -173,11 +204,17 @@ static BROTLI_INLINE int TransformDictionaryWord(
const char* prefix = kTransforms[transform].prefix;
const char* suffix = kTransforms[transform].suffix;
const int t = kTransforms[transform].transform;
int skip = t < kOmitFirst1 ? 0 : t - (kOmitFirst1 - 1);
int idx = 0;
int i = 0;
uint8_t* uppercase;
if (skip > len) {
skip = len;
}
while (*prefix) { dst[idx++] = (uint8_t)*prefix++; }
if (t <= kOmit9) {
word += skip;
len -= skip;
if (t <= kOmitLast9) {
len -= t;
}
while (i < len) { dst[idx++] = word[i++]; }

File diff suppressed because it is too large Load Diff

View File

@ -909,12 +909,13 @@ void BrotliCompressor::StoreDictionaryWordHashes() {
if (static_dictionary_ == NULL) {
static_dictionary_ = new StaticDictionary;
for (int t = num_transforms - 1; t >= 0; --t) {
for (int i = kMaxDictionaryWordLength; i >= 3; --i) {
for (int i = kMaxDictionaryWordLength;
i >= kMinDictionaryWordLength; --i) {
const int num_words = 1 << kBrotliDictionarySizeBitsByLength[i];
for (int j = num_words - 1; j >= 0; --j) {
int word_id = t * num_words + j;
std::string word = GetTransformedDictionaryWord(i, word_id);
if (word.size() >= 3) {
if (word.size() >= 4) {
static_dictionary_->Insert(word, i, word_id);
}
}

View File

@ -193,7 +193,7 @@ class HashLongestMatch {
literal_cost[(cur_ix + 1) & ring_buffer_mask] + 1.2;
bool match_found = false;
// Don't accept a short copy from far away.
double best_score = 8.11;
double best_score = 8.115;
if (insert_length_ < 4) {
double cost_diff[4] = { 0.10, 0.04, 0.02, 0.01 };
best_score += cost_diff[insert_length_];

View File

@ -118,6 +118,13 @@ void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
lit_cost *= 0.5;
lit_cost += 0.5;
}
// Make the first bytes more expensive -- seems to help, not sure why.
// Perhaps because the entropy source is changing its properties
// rapidly in the beginning of the file, perhaps because the beginning
// of the data is a statistical "anomaly".
if (i < 2000) {
lit_cost += 0.7 - ((2000 - i) / 2000.0 * 0.35);
}
cost[(pos + i) & cost_mask] = lit_cost;
}
}

View File

@ -25,17 +25,26 @@ namespace brotli {
enum WordTransformType {
kIdentity = 0,
kOmit1 = 1,
kOmit2 = 2,
kOmit3 = 3,
kOmit4 = 4,
kOmit5 = 5,
kOmit6 = 6,
kOmit7 = 7,
kOmit8 = 8,
kOmit9 = 9,
kOmitLast1 = 1,
kOmitLast2 = 2,
kOmitLast3 = 3,
kOmitLast4 = 4,
kOmitLast5 = 5,
kOmitLast6 = 6,
kOmitLast7 = 7,
kOmitLast8 = 8,
kOmitLast9 = 9,
kUppercaseFirst = 10,
kUppercaseAll = 11,
kOmitFirst1 = 12,
kOmitFirst2 = 13,
kOmitFirst3 = 14,
kOmitFirst4 = 15,
kOmitFirst5 = 16,
kOmitFirst6 = 17,
kOmitFirst7 = 18,
kOmitFirst8 = 19,
kOmitFirst9 = 20,
};
struct Transform {
@ -45,105 +54,127 @@ struct Transform {
};
static const Transform kTransforms[] = {
{ "", kIdentity, "" },
{ "", kIdentity, " ", },
{ "", kIdentity, "\">" },
{ "", kUppercaseFirst, "" },
{ "", kIdentity, "\"" },
{ "", kIdentity, ".", },
{ "", kIdentity, "=\"" },
{ "", kUppercaseFirst, " ", },
{ " ", kIdentity, "=\"" },
{ " ", kIdentity, " ", },
{ "", kIdentity, ":", },
{ " ", kIdentity, "" },
{ "", kIdentity, "\n" },
{ "", kIdentity, "(", },
{ "", kUppercaseAll, "" },
{ ".", kIdentity, "(", },
{ "", kIdentity, "'" },
{ "", kUppercaseFirst, "\"" },
{ " ", kUppercaseFirst, " ", },
{ "", kOmit3, "" },
{ "", kOmit4, "" },
{ ".", kIdentity, "" },
{ "", kOmit1, "" },
{ "", kOmit2, "" },
{ "", kUppercaseFirst, "\">" },
{ "", kOmit5, "" },
{ "", kUppercaseAll, " ", },
{ " ", kUppercaseFirst, "" },
{ "", kIdentity, ", ", },
{ "", kUppercaseFirst, "(", },
{ "", kIdentity, "\n\t" },
{ "", kUppercaseFirst, "'" },
{ ".", kIdentity, " ", },
{ " ", kUppercaseAll, " ", },
{ "", kIdentity, "='" },
{ "", kUppercaseFirst, ".", },
{ " ", kIdentity, ".", },
{ " ", kIdentity, ", ", },
{ " ", kUppercaseAll, "" },
{ "", kOmit6, "" },
{ "", kOmit9, "" },
{ "", kUppercaseAll, "\"" },
{ "", kIdentity, " the " },
{ "", kIdentity, " in " },
{ "", kIdentity, " of " },
{ "", kIdentity, " to " },
{ "", kIdentity, " and " },
{ "", kIdentity, " is " },
{ "", kIdentity, " on " },
{ "", kIdentity, " by " },
{ "", kIdentity, " for " },
{ "", kIdentity, " with " },
{ "", kIdentity, " from " },
{ "", kIdentity, " as " },
{ "", kIdentity, " at " },
{ "", kIdentity, "er " },
{ " ", kIdentity, "='" },
{ "", kIdentity, " a " },
{ "", kOmit7, "" },
{ "", kOmit8, "" },
{ " ", kIdentity, "(", },
{ " ", kIdentity, ". ", },
{ "", kIdentity, ". ", },
{ "", kIdentity, ",", },
{ "", kOmit1, "ing " },
{ "", kIdentity, "ed " },
{ "", kUppercaseFirst, ", ", },
{ "", kUppercaseAll, ".", },
{ "", kUppercaseAll, "=\"" },
{ "", kUppercaseAll, ", ", },
{ "", kUppercaseAll, "\">" },
{ " ", kUppercaseFirst, ".", },
{ " ", kUppercaseAll, "=\"" },
{ " ", kUppercaseFirst, ", ", },
{ "", kUppercaseAll, "'" },
{ "", kUppercaseFirst, "=\"" },
{ " ", kIdentity, ",", },
{ "", kIdentity, " that " },
{ "", kUppercaseFirst, "='" },
{ "", kUppercaseFirst, ". ", },
{ "", kUppercaseFirst, ",", },
{ "", kIdentity, ". The " },
{ "\xc2\xa0", kIdentity, "" },
{ " ", kUppercaseFirst, ". ", },
{ "", kUppercaseAll, ",", },
{ "", kUppercaseAll, "(", },
{ " ", kUppercaseAll, "='" },
{ "", kIdentity, "]" },
{ "", kUppercaseAll, "='" },
{ " ", kUppercaseAll, ".", },
{ "", kUppercaseAll, ". ", },
{ " ", kUppercaseFirst, "=\"" },
{ " ", kUppercaseAll, ". ", },
{ " ", kUppercaseFirst, ",", },
{ " ", kUppercaseAll, ", ", },
{ "", kIdentity, "ize " },
{ " ", kUppercaseFirst, "='" },
{ "", kIdentity, "est " },
{ "", kIdentity, ". This " },
{ "", kIdentity, "" },
{ "", kIdentity, " " },
{ " ", kIdentity, " " },
{ "", kOmitFirst1, "" },
{ "", kUppercaseFirst, " " },
{ "", kIdentity, " the " },
{ " ", kIdentity, "" },
{ "s ", kIdentity, " " },
{ "", kIdentity, " of " },
{ "", kUppercaseFirst, "" },
{ "", kIdentity, " and " },
{ "", kOmitFirst2, "" },
{ "", kOmitLast1, "" },
{ ", ", kIdentity, " " },
{ "", kIdentity, ", " },
{ " ", kUppercaseFirst, " " },
{ "", kIdentity, " in " },
{ "", kIdentity, " to " },
{ "e ", kIdentity, " " },
{ "", kIdentity, "\"" },
{ "", kIdentity, "." },
{ "", kIdentity, "\">" },
{ "", kIdentity, "\n" },
{ "", kOmitLast3, "" },
{ "", kIdentity, "]" },
{ "", kIdentity, " for " },
{ "", kOmitFirst3, "" },
{ "", kOmitLast2, "" },
{ "", kIdentity, " a " },
{ "", kIdentity, " that " },
{ " ", kUppercaseFirst, "" },
{ "", kIdentity, ". " },
{ ".", kIdentity, "" },
{ " ", kIdentity, ", " },
{ "", kOmitFirst4, "" },
{ "", kIdentity, " with " },
{ "", kIdentity, "'" },
{ "", kIdentity, " from " },
{ "", kIdentity, " by " },
{ "", kOmitFirst5, "" },
{ "", kOmitFirst6, "" },
{ " the ", kIdentity, "" },
{ "", kOmitLast4, "" },
{ "", kIdentity, ". The " },
{ "", kUppercaseAll, "" },
{ "", kIdentity, " on " },
{ "", kIdentity, " as " },
{ "", kIdentity, " is " },
{ "", kOmitLast7, "" },
{ "", kOmitLast1, "ing " },
{ "", kIdentity, "\n\t" },
{ "", kIdentity, ":" },
{ " ", kIdentity, ". " },
{ "", kIdentity, "ed " },
{ "", kOmitFirst9, "" },
{ "", kOmitFirst7, "" },
{ "", kOmitLast6, "" },
{ "", kIdentity, "(" },
{ "", kUppercaseFirst, ", " },
{ "", kOmitLast8, "" },
{ "", kIdentity, " at " },
{ "", kIdentity, "ly " },
{ " the ", kIdentity, " of " },
{ "", kOmitLast5, "" },
{ "", kOmitLast9, "" },
{ " ", kUppercaseFirst, ", " },
{ "", kUppercaseFirst, "\"" },
{ ".", kIdentity, "(" },
{ "", kUppercaseAll, " " },
{ "", kUppercaseFirst, "\">" },
{ "", kIdentity, "=\"" },
{ " ", kIdentity, "." },
{ ".com/", kIdentity, "" },
{ " the ", kIdentity, " of the " },
{ "", kUppercaseFirst, "'" },
{ "", kIdentity, ". This " },
{ "", kIdentity, "," },
{ ".", kIdentity, " " },
{ "", kUppercaseFirst, "(" },
{ "", kUppercaseFirst, "." },
{ "", kIdentity, " not " },
{ " ", kIdentity, "=\"" },
{ "", kIdentity, "er " },
{ " ", kUppercaseAll, " " },
{ "", kIdentity, "al " },
{ " ", kUppercaseAll, "" },
{ "", kIdentity, "='" },
{ "", kUppercaseAll, "\"" },
{ "", kUppercaseFirst, ". " },
{ " ", kIdentity, "(" },
{ "", kIdentity, "ful " },
{ " ", kUppercaseFirst, ". " },
{ "", kIdentity, "ive " },
{ "", kIdentity, "less " },
{ "", kUppercaseAll, "'" },
{ "", kIdentity, "est " },
{ " ", kUppercaseFirst, "." },
{ "", kUppercaseAll, "\">" },
{ " ", kIdentity, "='" },
{ "", kUppercaseFirst, "," },
{ "", kIdentity, "ize " },
{ "", kUppercaseAll, "." },
{ "\xc2\xa0", kIdentity, "" },
{ " ", kIdentity, "," },
{ "", kUppercaseFirst, "=\"" },
{ "", kUppercaseAll, "=\"" },
{ "", kIdentity, "ous " },
{ "", kUppercaseAll, ", " },
{ "", kUppercaseFirst, "='" },
{ " ", kUppercaseFirst, "," },
{ " ", kUppercaseAll, "=\"" },
{ " ", kUppercaseAll, ", " },
{ "", kUppercaseAll, "," },
{ "", kUppercaseAll, "(" },
{ "", kUppercaseAll, ". " },
{ " ", kUppercaseAll, "." },
{ "", kUppercaseAll, "='" },
{ " ", kUppercaseAll, ". " },
{ " ", kUppercaseFirst, "=\"" },
{ " ", kUppercaseAll, "='" },
{ " ", kUppercaseFirst, "='" },
};
static const int kNumTransforms = sizeof(kTransforms) / sizeof(kTransforms[0]);
@ -169,19 +200,26 @@ static int ToUpperCase(uint8_t *p, int len) {
inline std::string ApplyTransform(
const Transform& t, const uint8_t* word, int len) {
std::string ret(t.prefix);
if (t.word_transform <= kOmit9) {
if (t.word_transform <= kOmitLast9) {
len -= t.word_transform;
}
if (len > 0) {
ret += std::string(word, word + len);
uint8_t *uppercase = reinterpret_cast<uint8_t*>(&ret[ret.size() - len]);
if (t.word_transform == kUppercaseFirst) {
ToUpperCase(uppercase, len);
} else if (t.word_transform == kUppercaseAll) {
while (len > 0) {
int step = ToUpperCase(uppercase, len);
uppercase += step;
len -= step;
if (t.word_transform >= kOmitFirst1) {
const int skip = t.word_transform - (kOmitFirst1 - 1);
if (len > skip) {
ret += std::string(word + skip, word + len);
}
} else {
ret += std::string(word, word + len);
uint8_t *uppercase = reinterpret_cast<uint8_t*>(&ret[ret.size() - len]);
if (t.word_transform == kUppercaseFirst) {
ToUpperCase(uppercase, len);
} else if (t.word_transform == kUppercaseAll) {
while (len > 0) {
int step = ToUpperCase(uppercase, len);
uppercase += step;
len -= step;
}
}
}
}