1 /*
2  * This file is part of the Zephir.
3  *
4  * (c) Phalcon Team <team@zephir-lang.com>
5  *
6  * For the full copyright and license information, please view the LICENSE
7  * file that was distributed with this source code. If you did not receive
8  * a copy of the license it is available through the world-wide-web at the
9  * following url: https://docs.zephir-lang.com/en/latest/license
10  */
11 
12 #ifndef ZEPHIR_KERNEL_STRING_H
13 #define ZEPHIR_KERNEL_STRING_H
14 
15 #include <php.h>
16 #include <Zend/zend.h>
17 #include <zend_smart_str.h>
18 #include "kernel/main.h"
19 
20 #define ZEPHIR_TRIM_LEFT  1
21 #define ZEPHIR_TRIM_RIGHT 2
22 #define ZEPHIR_TRIM_BOTH  3
23 #define ZEPHIR_SUBSTR_NO_LENGTH 1
24 
25 /** Fast char position */
26 int zephir_memnstr(const zval *haystack, const zval *needle ZEPHIR_DEBUG_PARAMS);
27 int zephir_memnstr_str(const zval *haystack, char *needle, unsigned int needle_length ZEPHIR_DEBUG_PARAMS);
28 
29 int zephir_fast_strlen_ev(zval *str);
30 void zephir_fast_strtolower(zval *return_value, zval *str);
31 void zephir_fast_strtoupper(zval *return_value, zval *str);
32 void zephir_fast_join(zval *result, zval *glue, zval *pieces);
33 void zephir_fast_join_str(zval *result, char *glue, unsigned int glue_length, zval *pieces);
34 void zephir_fast_explode(zval *result, zval *delimiter, zval *str, long limit);
35 void zephir_fast_explode_str(zval *result, const char *delimiter, int delimiter_length, zval *str, long limit);
36 void zephir_fast_strpos(zval *return_value, const zval *haystack, const zval *needle, unsigned int offset);
37 void zephir_fast_strpos_str(zval *return_value, const zval *haystack, char *needle, unsigned int needle_length);
38 void zephir_fast_trim(zval *return_value, zval *str, zval *charlist, int where);
39 void zephir_fast_str_replace(zval *return_value, zval *search, zval *replace, zval *subject);
40 
41 void zephir_camelize(zval *return_value, const zval *str, const zval *delimiter);
42 void zephir_uncamelize(zval *return_value, const zval *str, const zval *delimiter);
43 
44 /** Starts/Ends with */
45 int zephir_start_with(const zval *str, const zval *compared, zval *case_sensitive);
46 int zephir_start_with_str(const zval *str, char *compared, unsigned int compared_length);
47 int zephir_start_with_str_str(char *str, unsigned int str_length, char *compared, unsigned int compared_length);
48 
49 int zephir_end_with(const zval *str, const zval *compared, zval *case_sensitive);
50 int zephir_end_with_str(const zval *str, char *compared, unsigned int compared_length);
51 
52 /** spprintf */
53 int zephir_spprintf(char **message, int max_len, char *format, ...);
54 
55 /** JSON */
56 int zephir_json_encode(zval *return_value, zval *v, int opts);
57 int zephir_json_decode(zval *return_value, zval *v, zend_bool assoc);
58 
59 /* Substr */
60 void zephir_substr(zval *return_value, zval *str, long from, long length, int flags);
61 
62 /** Preg-Match */
63 void zephir_preg_match(zval *return_value, zval *regex, zval *subject, zval *matches, int global, long flags, long offset);
64 
65 /** Hash */
66 void zephir_md5(zval *return_value, zval *str);
67 void zephir_crc32(zval *return_value, zval *str);
68 
69 /** */
70 void zephir_ucfirst(zval *return_value, zval *s);
71 void zephir_addslashes(zval *return_value, zval *str);
72 void zephir_stripslashes(zval *return_value, zval *str);
73 void zephir_stripcslashes(zval *return_value, zval *str);
74 void zephir_unique_key(zval *return_value, const zval *prefix, zval *value);
75 
76 void zephir_append_printable_array(smart_str *implstr, const zval *value);
77 
78 int zephir_hash_equals(const zval *known_zval, const zval *user_zval);
79 
80 void zephir_string_to_hex(zval *return_value, zval *var);
81 
82 #endif /* ZEPHIR_KERNEL_STRING_H */
83