| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 17 | #include <androidfw/BigBuffer.h> | 
|  | 18 | #include <androidfw/StringPool.h> | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 19 |  | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 20 | #include <algorithm> | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 21 | #include <memory> | 
|  | 22 | #include <string> | 
|  | 23 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 24 | #include "android-base/logging.h" | 
|  | 25 | #include "androidfw/ResourceTypes.h" | 
| Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 26 | #include "androidfw/StringPiece.h" | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 27 | #include "androidfw/Util.h" | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 28 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 29 | using ::android::StringPiece; | 
| Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 30 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 31 | namespace android { | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 32 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 33 | StringPool::Ref::Ref() : entry_(nullptr) { | 
|  | 34 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 35 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 36 | StringPool::Ref::Ref(const StringPool::Ref& rhs) : entry_(rhs.entry_) { | 
|  | 37 | if (entry_ != nullptr) { | 
|  | 38 | entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 39 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 42 | StringPool::Ref::Ref(StringPool::Entry* entry) : entry_(entry) { | 
|  | 43 | if (entry_ != nullptr) { | 
|  | 44 | entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 45 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 46 | } | 
|  | 47 |  | 
|  | 48 | StringPool::Ref::~Ref() { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 49 | if (entry_ != nullptr) { | 
|  | 50 | entry_->ref_--; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 51 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | StringPool::Ref& StringPool::Ref::operator=(const StringPool::Ref& rhs) { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 55 | if (rhs.entry_ != nullptr) { | 
|  | 56 | rhs.entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 57 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 58 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 59 | if (entry_ != nullptr) { | 
|  | 60 | entry_->ref_--; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 61 | } | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 62 | entry_ = rhs.entry_; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 63 | return *this; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
| Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 66 | bool StringPool::Ref::operator==(const Ref& rhs) const { | 
|  | 67 | return entry_->value == rhs.entry_->value; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | bool StringPool::Ref::operator!=(const Ref& rhs) const { | 
|  | 71 | return entry_->value != rhs.entry_->value; | 
|  | 72 | } | 
|  | 73 |  | 
| Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 74 | const std::string* StringPool::Ref::operator->() const { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 75 | return &entry_->value; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 78 | const std::string& StringPool::Ref::operator*() const { | 
|  | 79 | return entry_->value; | 
|  | 80 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 81 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 82 | size_t StringPool::Ref::index() const { | 
|  | 83 | // Account for the styles, which *always* come first. | 
|  | 84 | return entry_->pool_->styles_.size() + entry_->index_; | 
|  | 85 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 86 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 87 | const StringPool::Context& StringPool::Ref::GetContext() const { | 
|  | 88 | return entry_->context; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 91 | StringPool::StyleRef::StyleRef() : entry_(nullptr) { | 
|  | 92 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 93 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 94 | StringPool::StyleRef::StyleRef(const StringPool::StyleRef& rhs) : entry_(rhs.entry_) { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 95 | if (entry_ != nullptr) { | 
|  | 96 | entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 97 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 100 | StringPool::StyleRef::StyleRef(StringPool::StyleEntry* entry) : entry_(entry) { | 
|  | 101 | if (entry_ != nullptr) { | 
|  | 102 | entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 103 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
|  | 106 | StringPool::StyleRef::~StyleRef() { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 107 | if (entry_ != nullptr) { | 
|  | 108 | entry_->ref_--; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 109 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 112 | StringPool::StyleRef& StringPool::StyleRef::operator=(const StringPool::StyleRef& rhs) { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 113 | if (rhs.entry_ != nullptr) { | 
|  | 114 | rhs.entry_->ref_++; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 115 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 116 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 117 | if (entry_ != nullptr) { | 
|  | 118 | entry_->ref_--; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 119 | } | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 120 | entry_ = rhs.entry_; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 121 | return *this; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
| Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 124 | bool StringPool::StyleRef::operator==(const StyleRef& rhs) const { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 125 | if (entry_->value != rhs.entry_->value) { | 
| Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 126 | return false; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | if (entry_->spans.size() != rhs.entry_->spans.size()) { | 
|  | 130 | return false; | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | auto rhs_iter = rhs.entry_->spans.begin(); | 
|  | 134 | for (const Span& span : entry_->spans) { | 
|  | 135 | const Span& rhs_span = *rhs_iter; | 
|  | 136 | if (span.first_char != rhs_span.first_char || span.last_char != rhs_span.last_char || | 
|  | 137 | span.name != rhs_span.name) { | 
|  | 138 | return false; | 
|  | 139 | } | 
|  | 140 | } | 
|  | 141 | return true; | 
|  | 142 | } | 
|  | 143 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 144 | bool StringPool::StyleRef::operator!=(const StyleRef& rhs) const { | 
|  | 145 | return !operator==(rhs); | 
|  | 146 | } | 
| Adam Lesinski | 7542162 | 2017-01-06 15:20:04 -0800 | [diff] [blame] | 147 |  | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 148 | const StringPool::StyleEntry* StringPool::StyleRef::operator->() const { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 149 | return entry_; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 150 | } | 
|  | 151 |  | 
|  | 152 | const StringPool::StyleEntry& StringPool::StyleRef::operator*() const { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 153 | return *entry_; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 156 | size_t StringPool::StyleRef::index() const { | 
|  | 157 | return entry_->index_; | 
|  | 158 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 159 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 160 | const StringPool::Context& StringPool::StyleRef::GetContext() const { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 161 | return entry_->context; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 162 | } | 
|  | 163 |  | 
| Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 164 | StringPool::Ref StringPool::MakeRef(StringPiece str) { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 165 | return MakeRefImpl(str, Context{}, true); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 166 | } | 
|  | 167 |  | 
| Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 168 | StringPool::Ref StringPool::MakeRef(StringPiece str, const Context& context) { | 
| Ryan Mitchell | 90b7a08 | 2019-02-15 17:39:58 +0000 | [diff] [blame] | 169 | return MakeRefImpl(str, context, true); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
| Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 172 | StringPool::Ref StringPool::MakeRefImpl(StringPiece str, const Context& context, bool unique) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 173 | if (unique) { | 
| y | 4602926 | 2018-04-16 18:13:14 -0700 | [diff] [blame] | 174 | auto range = indexed_strings_.equal_range(str); | 
|  | 175 | for (auto iter = range.first; iter != range.second; ++iter) { | 
|  | 176 | if (context.priority == iter->second->context.priority) { | 
|  | 177 | return Ref(iter->second); | 
|  | 178 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 179 | } | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 180 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 181 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 182 | std::unique_ptr<Entry> entry(new Entry()); | 
| Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 183 | entry->value = std::string(str); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 184 | entry->context = context; | 
| Ryan Mitchell | 90b7a08 | 2019-02-15 17:39:58 +0000 | [diff] [blame] | 185 | entry->index_ = strings_.size(); | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 186 | entry->ref_ = 0; | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 187 | entry->pool_ = this; | 
|  | 188 |  | 
|  | 189 | Entry* borrow = entry.get(); | 
| Ryan Mitchell | 90b7a08 | 2019-02-15 17:39:58 +0000 | [diff] [blame] | 190 | strings_.emplace_back(std::move(entry)); | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 191 | indexed_strings_.insert(std::make_pair(StringPiece(borrow->value), borrow)); | 
|  | 192 | return Ref(borrow); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 193 | } | 
|  | 194 |  | 
| Adam Lesinski | 8a0b238 | 2017-10-18 15:07:33 -0700 | [diff] [blame] | 195 | StringPool::Ref StringPool::MakeRef(const Ref& ref) { | 
|  | 196 | if (ref.entry_->pool_ == this) { | 
|  | 197 | return ref; | 
|  | 198 | } | 
|  | 199 | return MakeRef(ref.entry_->value, ref.entry_->context); | 
|  | 200 | } | 
|  | 201 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 202 | StringPool::StyleRef StringPool::MakeRef(const StyleString& str) { | 
|  | 203 | return MakeRef(str, Context{}); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 204 | } | 
|  | 205 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 206 | StringPool::StyleRef StringPool::MakeRef(const StyleString& str, const Context& context) { | 
|  | 207 | std::unique_ptr<StyleEntry> entry(new StyleEntry()); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 208 | entry->value = str.str; | 
|  | 209 | entry->context = context; | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 210 | entry->index_ = styles_.size(); | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 211 | entry->ref_ = 0; | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 212 | for (const android::Span& span : str.spans) { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 213 | entry->spans.emplace_back(Span{MakeRef(span.name), span.first_char, span.last_char}); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 214 | } | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 215 |  | 
|  | 216 | StyleEntry* borrow = entry.get(); | 
|  | 217 | styles_.emplace_back(std::move(entry)); | 
|  | 218 | return StyleRef(borrow); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 221 | StringPool::StyleRef StringPool::MakeRef(const StyleRef& ref) { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 222 | std::unique_ptr<StyleEntry> entry(new StyleEntry()); | 
|  | 223 | entry->value = ref.entry_->value; | 
|  | 224 | entry->context = ref.entry_->context; | 
|  | 225 | entry->index_ = styles_.size(); | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 226 | entry->ref_ = 0; | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 227 | for (const Span& span : ref.entry_->spans) { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 228 | entry->spans.emplace_back(Span{MakeRef(*span.name), span.first_char, span.last_char}); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 229 | } | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 230 |  | 
|  | 231 | StyleEntry* borrow = entry.get(); | 
|  | 232 | styles_.emplace_back(std::move(entry)); | 
|  | 233 | return StyleRef(borrow); | 
|  | 234 | } | 
|  | 235 |  | 
|  | 236 | void StringPool::ReAssignIndices() { | 
|  | 237 | // Assign the style indices. | 
|  | 238 | const size_t style_len = styles_.size(); | 
|  | 239 | for (size_t index = 0; index < style_len; index++) { | 
|  | 240 | styles_[index]->index_ = index; | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | // Assign the string indices. | 
|  | 244 | const size_t string_len = strings_.size(); | 
|  | 245 | for (size_t index = 0; index < string_len; index++) { | 
|  | 246 | strings_[index]->index_ = index; | 
|  | 247 | } | 
| Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 248 | } | 
|  | 249 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 250 | void StringPool::Merge(StringPool&& pool) { | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 251 | // First, change the owning pool for the incoming strings. | 
|  | 252 | for (std::unique_ptr<Entry>& entry : pool.strings_) { | 
|  | 253 | entry->pool_ = this; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 254 | } | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 255 |  | 
|  | 256 | // Now move the styles, strings, and indices over. | 
|  | 257 | std::move(pool.styles_.begin(), pool.styles_.end(), std::back_inserter(styles_)); | 
|  | 258 | pool.styles_.clear(); | 
|  | 259 | std::move(pool.strings_.begin(), pool.strings_.end(), std::back_inserter(strings_)); | 
|  | 260 | pool.strings_.clear(); | 
|  | 261 | indexed_strings_.insert(pool.indexed_strings_.begin(), pool.indexed_strings_.end()); | 
|  | 262 | pool.indexed_strings_.clear(); | 
|  | 263 |  | 
|  | 264 | ReAssignIndices(); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 267 | void StringPool::HintWillAdd(size_t string_count, size_t style_count) { | 
|  | 268 | strings_.reserve(strings_.size() + string_count); | 
|  | 269 | styles_.reserve(styles_.size() + style_count); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 270 | } | 
|  | 271 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 272 | void StringPool::Prune() { | 
|  | 273 | const auto iter_end = indexed_strings_.end(); | 
|  | 274 | auto index_iter = indexed_strings_.begin(); | 
|  | 275 | while (index_iter != iter_end) { | 
|  | 276 | if (index_iter->second->ref_ <= 0) { | 
|  | 277 | index_iter = indexed_strings_.erase(index_iter); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 278 | } else { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 279 | ++index_iter; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 280 | } | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 281 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 282 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 283 | auto end_iter2 = | 
|  | 284 | std::remove_if(strings_.begin(), strings_.end(), | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 285 | [](const std::unique_ptr<Entry>& entry) -> bool { return entry->ref_ <= 0; }); | 
|  | 286 | auto end_iter3 = std::remove_if( | 
|  | 287 | styles_.begin(), styles_.end(), | 
|  | 288 | [](const std::unique_ptr<StyleEntry>& entry) -> bool { return entry->ref_ <= 0; }); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 289 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 290 | // Remove the entries at the end or else we'll be accessing a deleted string from the StyleEntry. | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 291 | strings_.erase(end_iter2, strings_.end()); | 
|  | 292 | styles_.erase(end_iter3, styles_.end()); | 
| Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 293 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 294 | ReAssignIndices(); | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | template <typename E> | 
|  | 298 | static void SortEntries( | 
|  | 299 | std::vector<std::unique_ptr<E>>& entries, | 
|  | 300 | const std::function<int(const StringPool::Context&, const StringPool::Context&)>& cmp) { | 
|  | 301 | using UEntry = std::unique_ptr<E>; | 
|  | 302 |  | 
|  | 303 | if (cmp != nullptr) { | 
|  | 304 | std::sort(entries.begin(), entries.end(), [&cmp](const UEntry& a, const UEntry& b) -> bool { | 
|  | 305 | int r = cmp(a->context, b->context); | 
|  | 306 | if (r == 0) { | 
|  | 307 | r = a->value.compare(b->value); | 
|  | 308 | } | 
|  | 309 | return r < 0; | 
|  | 310 | }); | 
|  | 311 | } else { | 
|  | 312 | std::sort(entries.begin(), entries.end(), | 
|  | 313 | [](const UEntry& a, const UEntry& b) -> bool { return a->value < b->value; }); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 314 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 315 | } | 
|  | 316 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 317 | void StringPool::Sort(const std::function<int(const Context&, const Context&)>& cmp) { | 
|  | 318 | SortEntries(styles_, cmp); | 
|  | 319 | SortEntries(strings_, cmp); | 
|  | 320 | ReAssignIndices(); | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 321 | } | 
|  | 322 |  | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 323 | template <typename T> | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 324 | static T* EncodeLength(T* data, size_t length) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 325 | static_assert(std::is_integral<T>::value, "wat."); | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 326 |  | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 327 | constexpr size_t kMask = 1 << ((sizeof(T) * 8) - 1); | 
|  | 328 | constexpr size_t kMaxSize = kMask - 1; | 
|  | 329 | if (length > kMaxSize) { | 
|  | 330 | *data++ = kMask | (kMaxSize & (length >> (sizeof(T) * 8))); | 
|  | 331 | } | 
|  | 332 | *data++ = length; | 
|  | 333 | return data; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 334 | } | 
|  | 335 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 336 | /** | 
|  | 337 | * Returns the maximum possible string length that can be successfully encoded | 
|  | 338 | * using 2 units of the specified T. | 
|  | 339 | *    EncodeLengthMax<char> -> maximum unit length of 0x7FFF | 
|  | 340 | *    EncodeLengthMax<char16_t> -> maximum unit length of 0x7FFFFFFF | 
|  | 341 | **/ | 
|  | 342 | template <typename T> | 
|  | 343 | static size_t EncodeLengthMax() { | 
|  | 344 | static_assert(std::is_integral<T>::value, "wat."); | 
|  | 345 |  | 
|  | 346 | constexpr size_t kMask = 1 << ((sizeof(T) * 8 * 2) - 1); | 
|  | 347 | constexpr size_t max = kMask - 1; | 
|  | 348 | return max; | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | /** | 
|  | 352 | * Returns the number of units (1 or 2) needed to encode the string length | 
|  | 353 | * before writing the string. | 
|  | 354 | */ | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 355 | template <typename T> | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 356 | static size_t EncodedLengthUnits(size_t length) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 357 | static_assert(std::is_integral<T>::value, "wat."); | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 358 |  | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 359 | constexpr size_t kMask = 1 << ((sizeof(T) * 8) - 1); | 
|  | 360 | constexpr size_t kMaxSize = kMask - 1; | 
|  | 361 | return length > kMaxSize ? 2 : 1; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 362 | } | 
|  | 363 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 364 | const std::string kStringTooLarge = "STRING_TOO_LARGE"; | 
|  | 365 |  | 
|  | 366 | static bool EncodeString(const std::string& str, const bool utf8, BigBuffer* out, | 
|  | 367 | IDiagnostics* diag) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 368 | if (utf8) { | 
| Ryan Mitchell | d86ea58 | 2018-06-27 11:57:18 -0700 | [diff] [blame] | 369 | const std::string& encoded = util::Utf8ToModifiedUtf8(str); | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 370 | const ssize_t utf16_length = | 
|  | 371 | utf8_to_utf16_length(reinterpret_cast<const uint8_t*>(encoded.data()), encoded.size()); | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 372 | CHECK(utf16_length >= 0); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 373 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 374 | // Make sure the lengths to be encoded do not exceed the maximum length that | 
|  | 375 | // can be encoded using chars | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 376 | if ((((size_t)encoded.size()) > EncodeLengthMax<char>()) || | 
|  | 377 | (((size_t)utf16_length) > EncodeLengthMax<char>())) { | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 378 | diag->Error(DiagMessage() << "string too large to encode using UTF-8 " | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 379 | << "written instead as '" << kStringTooLarge << "'"); | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 380 |  | 
|  | 381 | EncodeString(kStringTooLarge, utf8, out, diag); | 
|  | 382 | return false; | 
|  | 383 | } | 
|  | 384 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 385 | const size_t total_size = EncodedLengthUnits<char>(utf16_length) + | 
|  | 386 | EncodedLengthUnits<char>(encoded.size()) + encoded.size() + 1; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 387 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 388 | char* data = out->NextBlock<char>(total_size); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 389 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 390 | // First encode the UTF16 string length. | 
|  | 391 | data = EncodeLength(data, utf16_length); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 392 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 393 | // Now encode the size of the real UTF8 string. | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 394 | data = EncodeLength(data, encoded.size()); | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 395 | strncpy(data, encoded.data(), encoded.size()); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 396 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 397 | } else { | 
|  | 398 | const std::u16string encoded = util::Utf8ToUtf16(str); | 
|  | 399 | const ssize_t utf16_length = encoded.size(); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 400 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 401 | // Make sure the length to be encoded does not exceed the maximum possible | 
|  | 402 | // length that can be encoded | 
|  | 403 | if (((size_t)utf16_length) > EncodeLengthMax<char16_t>()) { | 
|  | 404 | diag->Error(DiagMessage() << "string too large to encode using UTF-16 " | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 405 | << "written instead as '" << kStringTooLarge << "'"); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 406 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 407 | EncodeString(kStringTooLarge, utf8, out, diag); | 
|  | 408 | return false; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 409 | } | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 410 |  | 
|  | 411 | // Total number of 16-bit words to write. | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 412 | const size_t total_size = EncodedLengthUnits<char16_t>(utf16_length) + encoded.size() + 1; | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 413 |  | 
|  | 414 | char16_t* data = out->NextBlock<char16_t>(total_size); | 
|  | 415 |  | 
|  | 416 | // Encode the actual UTF16 string length. | 
|  | 417 | data = EncodeLength(data, utf16_length); | 
|  | 418 | const size_t byte_length = encoded.size() * sizeof(char16_t); | 
|  | 419 |  | 
|  | 420 | // NOTE: For some reason, strncpy16(data, entry->value.data(), | 
|  | 421 | // entry->value.size()) truncates the string. | 
|  | 422 | memcpy(data, encoded.data(), byte_length); | 
|  | 423 |  | 
|  | 424 | // The null-terminating character is already here due to the block of data | 
|  | 425 | // being set to 0s on allocation. | 
|  | 426 | } | 
|  | 427 |  | 
|  | 428 | return true; | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 429 | } | 
|  | 430 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 431 | bool StringPool::Flatten(BigBuffer* out, const StringPool& pool, bool utf8, IDiagnostics* diag) { | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 432 | bool no_error = true; | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 433 | const size_t start_index = out->size(); | 
|  | 434 | android::ResStringPool_header* header = out->NextBlock<android::ResStringPool_header>(); | 
|  | 435 | header->header.type = util::HostToDevice16(android::RES_STRING_POOL_TYPE); | 
|  | 436 | header->header.headerSize = util::HostToDevice16(sizeof(*header)); | 
|  | 437 | header->stringCount = util::HostToDevice32(pool.size()); | 
|  | 438 | header->styleCount = util::HostToDevice32(pool.styles_.size()); | 
|  | 439 | if (utf8) { | 
|  | 440 | header->flags |= android::ResStringPool_header::UTF8_FLAG; | 
|  | 441 | } | 
|  | 442 |  | 
|  | 443 | uint32_t* indices = pool.size() != 0 ? out->NextBlock<uint32_t>(pool.size()) : nullptr; | 
|  | 444 | uint32_t* style_indices = | 
|  | 445 | pool.styles_.size() != 0 ? out->NextBlock<uint32_t>(pool.styles_.size()) : nullptr; | 
|  | 446 |  | 
|  | 447 | const size_t before_strings_index = out->size(); | 
|  | 448 | header->stringsStart = before_strings_index - start_index; | 
|  | 449 |  | 
|  | 450 | // Styles always come first. | 
|  | 451 | for (const std::unique_ptr<StyleEntry>& entry : pool.styles_) { | 
|  | 452 | *indices++ = out->size() - before_strings_index; | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 453 | no_error = EncodeString(entry->value, utf8, out, diag) && no_error; | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 454 | } | 
|  | 455 |  | 
|  | 456 | for (const std::unique_ptr<Entry>& entry : pool.strings_) { | 
|  | 457 | *indices++ = out->size() - before_strings_index; | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 458 | no_error = EncodeString(entry->value, utf8, out, diag) && no_error; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 459 | } | 
|  | 460 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 461 | out->Align4(); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 462 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 463 | if (style_indices != nullptr) { | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 464 | const size_t before_styles_index = out->size(); | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 465 | header->stylesStart = util::HostToDevice32(before_styles_index - start_index); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 466 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 467 | for (const std::unique_ptr<StyleEntry>& entry : pool.styles_) { | 
|  | 468 | *style_indices++ = out->size() - before_styles_index; | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 469 |  | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 470 | if (!entry->spans.empty()) { | 
|  | 471 | android::ResStringPool_span* span = | 
|  | 472 | out->NextBlock<android::ResStringPool_span>(entry->spans.size()); | 
|  | 473 | for (const Span& s : entry->spans) { | 
|  | 474 | span->name.index = util::HostToDevice32(s.name.index()); | 
|  | 475 | span->firstChar = util::HostToDevice32(s.first_char); | 
|  | 476 | span->lastChar = util::HostToDevice32(s.last_char); | 
|  | 477 | span++; | 
|  | 478 | } | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 479 | } | 
|  | 480 |  | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 481 | uint32_t* spanEnd = out->NextBlock<uint32_t>(); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 482 | *spanEnd = android::ResStringPool_span::END; | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 483 | } | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 484 |  | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 485 | // The error checking code in the platform looks for an entire | 
|  | 486 | // ResStringPool_span structure worth of 0xFFFFFFFF at the end | 
|  | 487 | // of the style block, so fill in the remaining 2 32bit words | 
|  | 488 | // with 0xFFFFFFFF. | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 489 | const size_t padding_length = | 
|  | 490 | sizeof(android::ResStringPool_span) - sizeof(android::ResStringPool_span::name); | 
| Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 491 | uint8_t* padding = out->NextBlock<uint8_t>(padding_length); | 
|  | 492 | memset(padding, 0xff, padding_length); | 
|  | 493 | out->Align4(); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 494 | } | 
| Adam Lesinski | 5b6ee11 | 2017-07-28 17:10:35 -0700 | [diff] [blame] | 495 | header->header.size = util::HostToDevice32(out->size() - start_index); | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 496 | return no_error; | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 497 | } | 
|  | 498 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 499 | bool StringPool::FlattenUtf8(BigBuffer* out, const StringPool& pool, IDiagnostics* diag) { | 
|  | 500 | return Flatten(out, pool, true, diag); | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 501 | } | 
|  | 502 |  | 
| Ryan Mitchell | 70414f2 | 2018-03-26 11:05:31 -0700 | [diff] [blame] | 503 | bool StringPool::FlattenUtf16(BigBuffer* out, const StringPool& pool, IDiagnostics* diag) { | 
|  | 504 | return Flatten(out, pool, false, diag); | 
| Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 505 | } | 
|  | 506 |  | 
| Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 507 | }  // namespace android |