This fixes a bug in PHP/HH's crypt_blowfish implementation that can cause a short...
[hiphop-php.git] / hphp / util / text-util.h
blobb077d94a4e63d7ce89f53d2b0b50ddb038871a9d
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 #pragma once
21 #include <string>
22 #include <vector>
24 #include <folly/Range.h>
26 #include "hphp/util/portability.h"
28 namespace HPHP {
30 /**
31 * Replace all occurrences of "from" substring to "to" string.
33 void replaceAll(std::string &s, const char *from, const char *to);
35 /**
36 * Change an ASCII string to lower case.
38 std::string toLower(folly::StringPiece s);
40 /**
41 * Change an ASCII string to upper case.
43 std::string toUpper(folly::StringPiece s);
45 /**
46 * Convert a full pathname of a file to an identifier.
48 std::string getIdentifier(const std::string &fileName);
50 /**
51 * Duplicate a buffer of given size, null-terminate the result.
53 const void *buffer_duplicate(const void *src, size_t size);
55 /**
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);
61 /**
62 * printf into a std::string.
64 void string_printf(std::string &msg,
65 ATTRIBUTE_PRINTF_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2,3);
67 /**
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());
84 /**
85 * Format a regex pattern by surrounding with slashes and escaping pattern.
87 std::string format_pattern(const std::string &pattern, bool prefixSlash);
89 } // namespace HPHP