blob: 227c651845389e1044981af271c47bb6807c53f3 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_STRING_UTILS_H_
#define BASE_STRING_UTILS_H_
#include <string>
#include <vector>
namespace base {
constexpr char16_t kWhitespaceUTF16 = u' ';
// Return a C++ string given printf-like input.
template <typename... Args>
std::string StringPrintf(const std::string& format, Args... args) {
// Calculate the buffer size.
int size = snprintf(nullptr, 0, format.c_str(), args...) + 1;
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
}
std::u16string ASCIIToUTF16(std::string src);
std::u16string UTF8ToUTF16(std::string src);
std::string UTF16ToUTF8(std::u16string src);
std::u16string NumberToString16(float number);
std::string NumberToString(unsigned int number);
std::string NumberToString(int32_t number);
std::string NumberToString(float number);
std::string ToUpperASCII(std::string str);
std::string ToLowerASCII(std::string str);
std::string JoinString(std::vector<std::string> tokens, std::string delimiter);
void ReplaceChars(std::string in,
std::string from,
std::string to,
std::string* out);
bool LowerCaseEqualsASCII(std::string a, std::string b);
bool ContainsOnlyChars(std::u16string str, char16_t ch);
const std::string& EmptyString();
} // namespace base
#endif // BASE_STRING_UTILS_H_