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