*/
NJS_EXPORT njs_int_t njs_vm_value_string(njs_vm_t *vm, njs_str_t *dst,
njs_value_t *src);
+/*
+ * If string value is null-terminated the corresponding C string
+ * is returned as is, otherwise the new copy is allocated with
+ * the terminating zero byte.
+ */
+NJS_EXPORT const char *njs_vm_value_to_c_string(njs_vm_t *vm,
+ njs_value_t *value);
NJS_EXPORT njs_int_t njs_vm_retval_string(njs_vm_t *vm, njs_str_t *dst);
NJS_EXPORT njs_int_t njs_vm_value_dump(njs_vm_t *vm, njs_str_t *dst,
}
-/*
- * If string value is null-terminated the corresponding C string
- * is returned as is, otherwise the new copy is allocated with
- * the terminating zero byte.
- */
-const char *
-njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value)
-{
- u_char *p, *data, *start;
- size_t size;
-
- if (value->short_string.size != NJS_STRING_LONG) {
- start = value->short_string.start;
- size = value->short_string.size;
-
- if (size < NJS_STRING_SHORT) {
- start[size] = '\0';
- return (const char *) start;
- }
-
- } else {
- start = value->long_string.data->start;
- size = value->long_string.size;
- }
-
- data = njs_mp_alloc(vm->mem_pool, size + 1);
- if (njs_slow_path(data == NULL)) {
- njs_memory_error(vm);
- return NULL;
- }
-
- p = njs_cpymem(data, start, size);
- *p++ = '\0';
-
- return (const char *) data;
-}
-
-
static const njs_object_prop_t njs_string_prototype_properties[] =
{
NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
uint32_t njs_string_index(njs_string_prop_t *string, uint32_t offset);
void njs_string_offset_map_init(const u_char *start, size_t size);
double njs_string_to_index(const njs_value_t *value);
-const char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value);
njs_int_t njs_string_encode_uri(njs_vm_t *vm, njs_value_t *args,
njs_uint_t nargs, njs_index_t component);
njs_int_t njs_string_decode_uri(njs_vm_t *vm, njs_value_t *args,
}
+/*
+ * If string value is null-terminated the corresponding C string
+ * is returned as is, otherwise the new copy is allocated with
+ * the terminating zero byte.
+ */
+const char *
+njs_vm_value_to_c_string(njs_vm_t *vm, njs_value_t *value)
+{
+ u_char *p, *data, *start;
+ size_t size;
+
+ njs_assert(njs_is_string(value));
+
+ if (value->short_string.size != NJS_STRING_LONG) {
+ start = value->short_string.start;
+ size = value->short_string.size;
+
+ if (size < NJS_STRING_SHORT) {
+ start[size] = '\0';
+ return (const char *) start;
+ }
+
+ } else {
+ start = value->long_string.data->start;
+ size = value->long_string.size;
+ }
+
+ data = njs_mp_alloc(vm->mem_pool, size + njs_length("\0"));
+ if (njs_slow_path(data == NULL)) {
+ njs_memory_error(vm);
+ return NULL;
+ }
+
+ p = njs_cpymem(data, start, size);
+ *p++ = '\0';
+
+ return (const char *) data;
+}
+
+
njs_int_t
njs_vm_value_to_bytes(njs_vm_t *vm, njs_str_t *dst, njs_value_t *src)
{