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.
19 #ifndef incl_HPHP_TEXT_UTIL_H_
20 #define incl_HPHP_TEXT_UTIL_H_
25 #include <folly/Range.h>
27 #include "hphp/util/portability.h"
32 * Replace all occurrences of "from" substring to "to" string.
34 void replaceAll(std::string
&s
, const char *from
, const char *to
);
37 * Change an ASCII string to lower case.
39 std::string
toLower(folly::StringPiece s
);
42 * Change an ASCII string to upper case.
44 std::string
toUpper(folly::StringPiece s
);
47 * Convert a full pathname of a file to an identifier.
49 std::string
getIdentifier(const std::string
&fileName
);
52 * Duplicate a buffer of given size, null-terminate the result.
54 const void *buffer_duplicate(const void *src
, size_t size
);
57 * Append buf2 to buf2, null-terminate the result.
59 const void *buffer_append(const void *buf1
, size_t size1
,
60 const void *buf2
, size_t size2
);
63 * printf into a std::string.
65 void string_printf(std::string
&msg
,
66 ATTRIBUTE_PRINTF_STRING
const char *fmt
, ...) ATTRIBUTE_PRINTF(2,3);
69 * Escaping strings for code generation.
71 std::string
escapeStringForCPP(const char *input
, int len
,
72 bool* binary
= nullptr);
74 inline std::string
escapeStringForCPP(const std::string
&input
,
75 bool* binary
= nullptr) {
76 return escapeStringForCPP(input
.data(), input
.length(), binary
);
79 std::string
escapeStringForPHP(const char *input
, int len
);
81 inline std::string
escapeStringForPHP(const std::string
&input
) {
82 return escapeStringForPHP(input
.data(), input
.length());
86 * Format a regex pattern by surrounding with slashes and escaping pattern.
88 std::string
format_pattern(const std::string
&pattern
, bool prefixSlash
);
92 #endif // incl_HPHP_TEXT_UTIL_H_