Flutter Engine
The Flutter Engine
strings.cc
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
6
7#include <cstdarg>
8
9namespace impeller {
10
12std::string SPrintF(const char* format, ...) {
13 std::string ret_val;
14 va_list list;
15 va_list list2;
16 va_start(list, format);
17 va_copy(list2, list);
18 if (auto string_length = ::vsnprintf(nullptr, 0, format, list);
19 string_length >= 0) {
20 auto buffer = reinterpret_cast<char*>(::malloc(string_length + 1));
21 ::vsnprintf(buffer, string_length + 1, format, list2);
22 ret_val = std::string{buffer, static_cast<size_t>(string_length)};
23 ::free(buffer);
24 }
25 va_end(list2);
26 va_end(list);
27 return ret_val;
28}
29
30bool HasPrefix(const std::string& string, const std::string& prefix) {
31 return string.find(prefix) == 0u;
32}
33
34bool HasSuffix(const std::string& string, const std::string& suffix) {
35 auto position = string.rfind(suffix);
36 if (position == std::string::npos) {
37 return false;
38 }
39 return position == string.size() - suffix.size();
40}
41
42std::string StripPrefix(const std::string& string,
43 const std::string& to_strip) {
44 if (!HasPrefix(string, to_strip)) {
45 return string;
46 }
47 return string.substr(to_strip.length());
48}
49
50} // namespace impeller
#define IMPELLER_PRINTF_FORMAT(format_number, args_number)
Definition: config.h:22
uint32_t uint32_t * format
va_start(args, format)
va_end(args)
void * malloc(size_t size)
Definition: allocation.cc:19
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
bool HasPrefix(const std::string &string, const std::string &prefix)
Definition: strings.cc:30
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
bool HasSuffix(const std::string &string, const std::string &suffix)
Definition: strings.cc:34
std::string StripPrefix(const std::string &string, const std::string &to_strip)
Definition: strings.cc:42
Definition: ref_ptr.h:256