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