File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -2181,6 +2181,30 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string
2181
2181
return ret_string_p ;
2182
2182
} /* ecma_string_trim */
2183
2183
2184
+ /**
2185
+ * Helper function for ecma_string conversion. It is used in
2186
+ * ECMA_STRING_TO_UTF8_STRING macro. Returns true if the output
2187
+ * buffer must be freed.
2188
+ *
2189
+ * @return true - if the output buffer must be freed.
2190
+ * false - otherwise
2191
+ */
2192
+ bool ecma_string_to_utf8_string (const ecma_string_t * ecma_str_ptr , /**< ecma string pointer */
2193
+ const lit_utf8_byte_t * * utf8_ptr , /**< [out] output buffer pointer */
2194
+ lit_utf8_size_t * utf8_str_size ) /**< [out] output buffer size */
2195
+ {
2196
+ * utf8_ptr = ecma_string_get_chars (ecma_str_ptr , utf8_str_size , NULL );
2197
+
2198
+ if (* utf8_ptr == NULL )
2199
+ {
2200
+ * utf8_ptr = (const lit_utf8_byte_t * ) jmem_heap_alloc_block (* utf8_str_size );
2201
+ ecma_string_to_utf8_bytes (ecma_str_ptr , (lit_utf8_byte_t * ) * utf8_ptr , * utf8_str_size );
2202
+ return true;
2203
+ }
2204
+
2205
+ return false;
2206
+ } /* ecma_string_to_utf8_string*/
2207
+
2184
2208
/**
2185
2209
* @}
2186
2210
* @}
Original file line number Diff line number Diff line change 50
50
*/
51
51
#define ECMA_SET_POINTER (field , non_compressed_pointer ) JMEM_CP_SET_POINTER (field, non_compressed_pointer)
52
52
53
+ bool ecma_string_to_utf8_string (const ecma_string_t * ecma_str_ptr ,
54
+ const lit_utf8_byte_t * * utf8_ptr ,
55
+ lit_utf8_size_t * utf8_str_size );
56
+
53
57
/**
54
58
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer.
55
59
*/
56
60
#define ECMA_STRING_TO_UTF8_STRING (ecma_str_ptr , /**< ecma string pointer */ \
57
61
utf8_ptr , /**< [out] output buffer pointer */ \
58
62
utf8_str_size ) /**< [out] output buffer size */ \
59
63
lit_utf8_size_t utf8_str_size; \
60
- const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, NULL); \
61
- bool utf8_ptr ## must_be_freed = false; \
62
- \
63
- if (utf8_ptr == NULL) \
64
- { \
65
- utf8_ptr = (const lit_utf8_byte_t *) jmem_heap_alloc_block (utf8_str_size); \
66
- ecma_string_to_utf8_bytes (ecma_str_ptr, (lit_utf8_byte_t *) utf8_ptr, utf8_str_size); \
67
- utf8_ptr ## must_be_freed = true; \
68
- }
64
+ const lit_utf8_byte_t *utf8_ptr = NULL; \
65
+ bool utf8_ptr ## must_be_freed = ecma_string_to_utf8_string (ecma_str_ptr, &utf8_ptr, &utf8_str_size);
69
66
70
67
#ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
71
68
You can’t perform that action at this time.
0 commit comments