2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 // Utilities for manipulating text in strings.
24 #include <folly/Range.h>
26 #include "hphp/util/portability.h"
31 * Replace all occurrences of "from" substring to "to" string.
33 void replaceAll(std::string
&s
, const char *from
, const char *to
);
36 * Change an ASCII string to lower case.
38 std::string
toLower(folly::StringPiece s
);
41 * Change an ASCII string to upper case.
43 std::string
toUpper(folly::StringPiece s
);
46 * Convert a full pathname of a file to an identifier.
48 std::string
getIdentifier(const std::string
&fileName
);
51 * Duplicate a buffer of given size, null-terminate the result.
53 const void *buffer_duplicate(const void *src
, size_t size
);
56 * Append buf2 to buf2, null-terminate the result.
58 const void *buffer_append(const void *buf1
, size_t size1
,
59 const void *buf2
, size_t size2
);
62 * printf into a std::string.
64 void string_printf(std::string
&msg
,
65 ATTRIBUTE_PRINTF_STRING
const char *fmt
, ...) ATTRIBUTE_PRINTF(2,3);
68 * Escaping strings for code generation.
70 std::string
escapeStringForCPP(const char *input
, int len
,
71 bool* binary
= nullptr);
73 inline std::string
escapeStringForCPP(const std::string
&input
,
74 bool* binary
= nullptr) {
75 return escapeStringForCPP(input
.data(), input
.length(), binary
);
78 std::string
escapeStringForPHP(const char *input
, int len
);
80 inline std::string
escapeStringForPHP(const std::string
&input
) {
81 return escapeStringForPHP(input
.data(), input
.length());
85 * Format a regex pattern by surrounding with slashes and escaping pattern.
87 std::string
format_pattern(const std::string
&pattern
, bool prefixSlash
);