Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
string_utils.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_STRING_UTILS_H_
6#define BASE_STRING_UTILS_H_
7
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace base {
13
14constexpr char16_t kWhitespaceUTF16 = u' ';
15
16// Return a C++ string given printf-like input.
17template <typename... Args>
18std::string StringPrintf(const std::string& format, Args... args) {
19 // Calculate the buffer size.
20 int size = snprintf(nullptr, 0, format.c_str(), args...) + 1;
21 std::unique_ptr<char[]> buf = std::make_unique<char[]>(size);
22 snprintf(buf.get(), size, format.c_str(), args...);
23 return std::string(buf.get(), buf.get() + size - 1);
24}
25
26std::u16string ASCIIToUTF16(std::string src);
27std::u16string UTF8ToUTF16(std::string src);
28std::string UTF16ToUTF8(std::u16string src);
29
30std::u16string NumberToString16(unsigned int number);
31std::u16string NumberToString16(int32_t number);
32std::u16string NumberToString16(float number);
33std::u16string NumberToString16(double number);
34
35std::string NumberToString(unsigned int number);
36std::string NumberToString(int32_t number);
37std::string NumberToString(float number);
38std::string NumberToString(double number);
39
40std::string ToUpperASCII(std::string str);
41std::string ToLowerASCII(std::string str);
42
43std::string JoinString(std::vector<std::string> tokens, std::string delimiter);
44std::u16string JoinString(std::vector<std::u16string> tokens,
45 std::u16string delimiter);
46
47void ReplaceChars(std::string in,
48 std::string from,
49 std::string to,
50 std::string* out);
51void ReplaceChars(std::u16string in,
52 std::u16string from,
53 std::u16string to,
54 std::u16string* out);
55bool LowerCaseEqualsASCII(std::string a, std::string b);
56bool ContainsOnlyChars(std::u16string str, char16_t ch);
57
58const std::string& EmptyString();
59
60} // namespace base
61
62#endif // BASE_STRING_UTILS_H_
static bool b
struct MyStruct a[10]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
std::string StringPrintf(const std::string &format, Args... args)
std::string ToUpperASCII(std::string str)
std::string UTF16ToUTF8(std::u16string src)
void ReplaceChars(std::string in, std::string from, std::string to, std::string *out)
const std::string & EmptyString()
std::u16string UTF8ToUTF16(std::string src)
constexpr char16_t kWhitespaceUTF16
bool ContainsOnlyChars(std::u16string str, char16_t ch)
std::u16string ASCIIToUTF16(std::string src)
std::string ToLowerASCII(std::string str)
std::string JoinString(std::vector< std::string > tokens, std::string delimiter)
bool LowerCaseEqualsASCII(std::string a, std::string b)
std::u16string NumberToString16(float number)