[njs] Added njs_primitive_value_to_number().

Dmitry Volyntsev xeioex at nginx.com
Fri Oct 19 18:30:54 UTC 2018


details:   http://hg.nginx.org/njs/rev/bd9f53d9de27
branches:  
changeset: 626:bd9f53d9de27
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Oct 19 20:55:30 2018 +0300
description:
Added njs_primitive_value_to_number().

diffstat:

 njs/njs_number.c |  18 ++++++++++++++++++
 njs/njs_number.h |   2 ++
 2 files changed, 20 insertions(+), 0 deletions(-)

diffs (40 lines):

diff -r 7e76c67af046 -r bd9f53d9de27 njs/njs_number.c
--- a/njs/njs_number.c	Fri Oct 19 20:55:23 2018 +0300
+++ b/njs/njs_number.c	Fri Oct 19 20:55:30 2018 +0300
@@ -64,6 +64,24 @@ njs_value_to_index(const njs_value_t *va
 
 
 double
+njs_primitive_value_to_number(const njs_value_t *value)
+{
+    if (nxt_fast_path(njs_is_numeric(value))) {
+        return value->data.u.number;
+    }
+
+    return njs_string_to_number(value, 1);
+}
+
+
+uint32_t
+njs_primitive_value_to_integer(const njs_value_t *value)
+{
+    return njs_number_to_integer(njs_primitive_value_to_number(value));
+}
+
+
+double
 njs_number_dec_parse(const u_char **start, const u_char *end)
 {
     return nxt_strtod(start, end);
diff -r 7e76c67af046 -r bd9f53d9de27 njs/njs_number.h
--- a/njs/njs_number.h	Fri Oct 19 20:55:23 2018 +0300
+++ b/njs/njs_number.h	Fri Oct 19 20:55:30 2018 +0300
@@ -13,6 +13,8 @@
 
 
 uint32_t njs_value_to_index(const njs_value_t *value);
+double njs_primitive_value_to_number(const njs_value_t *value);
+uint32_t njs_primitive_value_to_integer(const njs_value_t *value);
 double njs_number_dec_parse(const u_char **start, const u_char *end);
 uint64_t njs_number_oct_parse(const u_char **start, const u_char *end);
 uint64_t njs_number_bin_parse(const u_char **start, const u_char *end);


More information about the nginx-devel mailing list