2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 #ifndef incl_HPHP_STRING_UTIL_H_
18 #define incl_HPHP_STRING_UTIL_H_
20 #include "hphp/runtime/base/complex-types.h"
23 ///////////////////////////////////////////////////////////////////////////////
25 extern const StaticString k_HPHP_TRIM_CHARLIST
;
28 * Utility string functions. These are mostly wrappers around zend/ string
29 * functions, but in a safe and convenient form.
39 #define QUOTE_STYLES \
40 /* Use high values to avoid conflicts with currently unimplemented PHP ENT_
41 * constants and for possible future new constants in PHP */ \
42 QS(FBUtf8Only, 65536) \
44 /* Order of the fields matters here if we're
45 * matching on what flags are set */ \
46 QS(Ignore, 4) /* k_ENT_IGNORE: silently discard invalid chars */ \
47 QS(Both, 3) /* k_ENT_QUOTES: escape both double and single quotes */ \
48 QS(Double, 2) /* k_ENT_COMPAT: escape double quotes only */ \
49 QS(No, 0) /* k_ENT_NOQUOTES: leave all quotes alone */ \
51 #define QS(STYLE, VAL) STYLE = (VAL),
52 enum class QuoteStyle
{
57 static bool is_set(int64_t flags
, QuoteStyle qs
) {
58 auto as_int
= static_cast<int64_t>(qs
);
59 return (as_int
& flags
) == as_int
;
62 static QuoteStyle
toQuoteStyle(int64_t flags
) {
63 #define QS(STYLE, VAL) \
64 if (is_set(flags, QuoteStyle::STYLE)) { return QuoteStyle::STYLE; }
72 static int64_t toQuoteStyleBitmask(int64_t flags
) {
75 #define QS(STYLE, VAL) \
76 if (is_set(flags, QuoteStyle::STYLE)) { \
77 bitmask |= static_cast<int64_t>(QuoteStyle::STYLE); \
89 * Manipulations. Note, all these functions will create a new string than
90 * modifying input, although names of these functions sound like mutating.
92 static String
Pad(const String
& input
, int final_length
,
93 const String
& pad_string
= " ",
94 PadType type
= PadType::Right
);
95 static String
StripHTMLTags(const String
& input
,
96 const String
& allowable_tags
= "");
101 static Variant
Explode(const String
& input
, const String
& delimiter
,
102 int limit
= 0x7FFFFFFF);
103 static String
Implode(CVarRef items
, const String
& delim
); // == Join()
104 static Variant
Split(const String
& str
, int split_length
= 1);
105 static Variant
ChunkSplit(
106 const String
& body
, int chunklen
= 76,
107 const String
& end
= "\r\n"); // for email (rfc822/2822)
112 static String
HtmlEncode(const String
& input
, QuoteStyle quoteStyle
,
113 const char *charset
, bool nbsp
);
114 static String
HtmlEncode(const String
& input
, const int64_t qsBitmask
,
115 const char *charset
, bool nbsp
);
116 static String
HtmlEncodeExtra(const String
& input
, QuoteStyle quoteStyle
,
117 const char *charset
, bool nbsp
, Array extra
);
118 static String
HtmlDecode(const String
& input
, QuoteStyle quoteStyle
,
119 const char *charset
, bool all
);
120 static String
QuotedPrintableEncode(const String
& input
);
121 static String
QuotedPrintableDecode(const String
& input
);
122 static String
UUEncode(const String
& input
);
123 static String
UUDecode(const String
& input
);
124 static String
Base64Encode(const String
& input
);
125 static String
Base64Decode(const String
& input
, bool strict
= false);
126 static String
UrlEncode(const String
& input
, bool encodePlus
= true);
127 static String
UrlDecode(const String
& input
, bool decodePlus
= true);
132 static String
MoneyFormat(const char *format
, double value
);
137 static String
Translate(const String
& input
, const String
& from
,
139 static String
ROT13(const String
& input
);
140 static int64_t CRC32(const String
& input
);
141 static String
Crypt(const String
& input
, const char *salt
= "");
142 static String
MD5(const String
& input
, bool raw
= false);
143 static String
SHA1(const String
& input
, bool raw
= false);
146 ///////////////////////////////////////////////////////////////////////////////
149 #endif // incl_HPHP_STRING_UTIL_H_