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 | |
| 17 | #ifndef AAPT_UTIL_H |
| 18 | #define AAPT_UTIL_H |
| 19 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 20 | #include <functional> |
| 21 | #include <memory> |
| 22 | #include <ostream> |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 26 | #include "androidfw/ResourceTypes.h" |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 27 | #include "androidfw/StringPiece.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 28 | #include "utils/ByteOrder.h" |
| 29 | |
| 30 | #include "util/BigBuffer.h" |
| 31 | #include "util/Maybe.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 32 | |
| 33 | #ifdef _WIN32 |
| 34 | // TODO(adamlesinski): remove once http://b/32447322 is resolved. |
| 35 | // utils/ByteOrder.h includes winsock2.h on WIN32, |
| 36 | // which will pull in the ERROR definition. This conflicts |
| 37 | // with android-base/logging.h, which takes care of undefining |
| 38 | // ERROR, but it gets included too early (before winsock2.h). |
| 39 | #ifdef ERROR |
| 40 | #undef ERROR |
| 41 | #endif |
| 42 | #endif |
| 43 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 44 | namespace aapt { |
| 45 | namespace util { |
| 46 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 47 | std::vector<std::string> Split(const android::StringPiece& str, char sep); |
| 48 | std::vector<std::string> SplitAndLowercase(const android::StringPiece& str, char sep); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
Adam Lesinski | 4d3a987 | 2015-04-09 19:53:22 -0700 | [diff] [blame] | 51 | * Returns true if the string starts with prefix. |
| 52 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 53 | bool StartsWith(const android::StringPiece& str, const android::StringPiece& prefix); |
Adam Lesinski | 4d3a987 | 2015-04-09 19:53:22 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 56 | * Returns true if the string ends with suffix. |
| 57 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 58 | bool EndsWith(const android::StringPiece& str, const android::StringPiece& suffix); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Creates a new StringPiece16 that points to a substring |
| 62 | * of the original string without leading or trailing whitespace. |
| 63 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 64 | android::StringPiece TrimWhitespace(const android::StringPiece& str); |
Adam Lesinski | 3b4cd94 | 2015-10-30 16:31:42 -0700 | [diff] [blame] | 65 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 66 | /** |
| 67 | * UTF-16 isspace(). It basically checks for lower range characters that are |
| 68 | * whitespace. |
| 69 | */ |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 70 | inline bool isspace16(char16_t c) { return c < 0x0080 && isspace(c); } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Returns an iterator to the first character that is not alpha-numeric and that |
| 74 | * is not in the allowedChars set. |
| 75 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 76 | android::StringPiece::const_iterator FindNonAlphaNumericAndNotInSet( |
| 77 | const android::StringPiece& str, const android::StringPiece& allowed_chars); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 80 | * Tests that the string is a valid Java class name. |
| 81 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 82 | bool IsJavaClassName(const android::StringPiece& str); |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 85 | * Tests that the string is a valid Java package name. |
| 86 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 87 | bool IsJavaPackageName(const android::StringPiece& str); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 90 | * Converts the class name to a fully qualified class name from the given |
| 91 | * `package`. Ex: |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 92 | * |
| 93 | * asdf --> package.asdf |
| 94 | * .asdf --> package.asdf |
| 95 | * .a.b --> package.a.b |
| 96 | * asdf.adsf --> asdf.adsf |
| 97 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 98 | Maybe<std::string> GetFullyQualifiedClassName(const android::StringPiece& package, |
| 99 | const android::StringPiece& class_name); |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 102 | * Makes a std::unique_ptr<> with the template parameter inferred by the |
| 103 | * compiler. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 104 | * This will be present in C++14 and can be removed then. |
| 105 | */ |
| 106 | template <typename T, class... Args> |
| 107 | std::unique_ptr<T> make_unique(Args&&... args) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 108 | return std::unique_ptr<T>(new T{std::forward<Args>(args)...}); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 112 | * Writes a set of items to the std::ostream, joining the times with the |
| 113 | * provided |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 114 | * separator. |
| 115 | */ |
Adam Lesinski | 36c73a5 | 2016-08-11 13:39:24 -0700 | [diff] [blame] | 116 | template <typename Container> |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 117 | ::std::function<::std::ostream&(::std::ostream&)> Joiner( |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 118 | const Container& container, const char* sep) { |
| 119 | using std::begin; |
| 120 | using std::end; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 121 | const auto begin_iter = begin(container); |
| 122 | const auto end_iter = end(container); |
| 123 | return [begin_iter, end_iter, sep](::std::ostream& out) -> ::std::ostream& { |
| 124 | for (auto iter = begin_iter; iter != end_iter; ++iter) { |
| 125 | if (iter != begin_iter) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 126 | out << sep; |
| 127 | } |
| 128 | out << *iter; |
| 129 | } |
| 130 | return out; |
| 131 | }; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 134 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 135 | * Helper method to extract a UTF-16 string from a StringPool. If the string is |
| 136 | * stored as UTF-8, |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 137 | * the conversion to UTF-16 happens within ResStringPool. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 138 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 139 | android::StringPiece16 GetString16(const android::ResStringPool& pool, size_t idx); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 140 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 141 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 142 | * Helper method to extract a UTF-8 string from a StringPool. If the string is |
| 143 | * stored as UTF-16, |
| 144 | * the conversion from UTF-16 to UTF-8 does not happen in ResStringPool and is |
| 145 | * done by this method, |
| 146 | * which maintains no state or cache. This means we must return an std::string |
| 147 | * copy. |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 148 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 149 | std::string GetString(const android::ResStringPool& pool, size_t idx); |
Adam Lesinski | 28cacf0 | 2015-11-23 14:22:47 -0800 | [diff] [blame] | 150 | |
Adam Lesinski | b23f1e0 | 2015-11-03 12:24:17 -0800 | [diff] [blame] | 151 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 152 | * Checks that the Java string format contains no non-positional arguments |
| 153 | * (arguments without |
| 154 | * explicitly specifying an index) when there are more than one argument. This |
| 155 | * is an error |
| 156 | * because translations may rearrange the order of the arguments in the string, |
| 157 | * which will |
Adam Lesinski | b23f1e0 | 2015-11-03 12:24:17 -0800 | [diff] [blame] | 158 | * break the string interpolation. |
| 159 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 160 | bool VerifyJavaStringFormat(const android::StringPiece& str); |
Adam Lesinski | b23f1e0 | 2015-11-03 12:24:17 -0800 | [diff] [blame] | 161 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 162 | class StringBuilder { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 163 | public: |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 164 | StringBuilder& Append(const android::StringPiece& str); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 165 | const std::string& ToString() const; |
| 166 | const std::string& Error() const; |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 167 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 168 | // When building StyledStrings, we need UTF-16 indices into the string, |
| 169 | // which is what the Java layer expects when dealing with java |
| 170 | // String.charAt(). |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 171 | size_t Utf16Len() const; |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 172 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 173 | explicit operator bool() const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 174 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 175 | private: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 176 | std::string str_; |
| 177 | size_t utf16_len_ = 0; |
| 178 | bool quote_ = false; |
| 179 | bool trailing_space_ = false; |
| 180 | bool last_char_was_escape_ = false; |
| 181 | std::string error_; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 182 | }; |
| 183 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 184 | inline const std::string& StringBuilder::ToString() const { return str_; } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 185 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 186 | inline const std::string& StringBuilder::Error() const { return error_; } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 187 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 188 | inline size_t StringBuilder::Utf16Len() const { return utf16_len_; } |
Adam Lesinski | 8c3f31f | 2016-09-07 13:45:13 -0700 | [diff] [blame] | 189 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 190 | inline StringBuilder::operator bool() const { return error_.empty(); } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Converts a UTF8 string to a UTF16 string. |
| 194 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 195 | std::u16string Utf8ToUtf16(const android::StringPiece& utf8); |
| 196 | std::string Utf16ToUtf8(const android::StringPiece16& utf16); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Writes the entire BigBuffer to the output stream. |
| 200 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 201 | bool WriteAll(std::ostream& out, const BigBuffer& buffer); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Copies the entire BigBuffer into a single buffer. |
| 205 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 206 | std::unique_ptr<uint8_t[]> Copy(const BigBuffer& buffer); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * A Tokenizer implemented as an iterable collection. It does not allocate |
| 210 | * any memory on the heap nor use standard containers. |
| 211 | */ |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 212 | class Tokenizer { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 213 | public: |
| 214 | class iterator { |
| 215 | public: |
| 216 | iterator(const iterator&) = default; |
| 217 | iterator& operator=(const iterator&) = default; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 218 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 219 | iterator& operator++(); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 220 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 221 | android::StringPiece operator*() { return token_; } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 222 | bool operator==(const iterator& rhs) const; |
| 223 | bool operator!=(const iterator& rhs) const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 224 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 225 | private: |
| 226 | friend class Tokenizer; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 227 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 228 | iterator(android::StringPiece s, char sep, android::StringPiece tok, bool end); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 229 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 230 | android::StringPiece str_; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 231 | char separator_; |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 232 | android::StringPiece token_; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 233 | bool end_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 234 | }; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 235 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 236 | Tokenizer(android::StringPiece str, char sep); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 237 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 238 | iterator begin() { return begin_; } |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 239 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 240 | iterator end() { return end_; } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 241 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 242 | private: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 243 | const iterator begin_; |
| 244 | const iterator end_; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 245 | }; |
| 246 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 247 | inline Tokenizer Tokenize(const android::StringPiece& str, char sep) { return Tokenizer(str, sep); } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 248 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 249 | inline uint16_t HostToDevice16(uint16_t value) { return htods(value); } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 250 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 251 | inline uint32_t HostToDevice32(uint32_t value) { return htodl(value); } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 252 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 253 | inline uint16_t DeviceToHost16(uint16_t value) { return dtohs(value); } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 254 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 255 | inline uint32_t DeviceToHost32(uint32_t value) { return dtohl(value); } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 256 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 257 | /** |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 258 | * Given a path like: res/xml-sw600dp/foo.xml |
| 259 | * |
| 260 | * Extracts "res/xml-sw600dp/" into outPrefix. |
| 261 | * Extracts "foo" into outEntry. |
| 262 | * Extracts ".xml" into outSuffix. |
| 263 | * |
| 264 | * Returns true if successful. |
| 265 | */ |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame^] | 266 | bool ExtractResFilePathParts(const android::StringPiece& path, android::StringPiece* out_prefix, |
| 267 | android::StringPiece* out_entry, android::StringPiece* out_suffix); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 268 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 269 | } // namespace util |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 270 | |
| 271 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 272 | * Stream operator for functions. Calls the function with the stream as an |
| 273 | * argument. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 274 | * In the aapt namespace for lookup. |
| 275 | */ |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 276 | inline ::std::ostream& operator<<( |
| 277 | ::std::ostream& out, |
| 278 | const ::std::function<::std::ostream&(::std::ostream&)>& f) { |
| 279 | return f(out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 282 | } // namespace aapt |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 283 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 284 | #endif // AAPT_UTIL_H |