소스 검색

misc/parse_number.h: add generate_decimal_repr_string()

ambrop7 13 년 전
부모
커밋
88f5990427
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      misc/parse_number.h

+ 12 - 0
misc/parse_number.h

@@ -52,6 +52,7 @@ static int parse_unsigned_hex_integer (const char *str, uintmax_t *out) WARN_UNU
 // public generation functions
 static int compute_decimal_repr_size (uintmax_t x);
 static void generate_decimal_repr (uintmax_t x, char *out, int repr_size);
+static int generate_decimal_repr_string (uintmax_t x, char *out);
 
 // implementation follows
 
@@ -212,4 +213,15 @@ void generate_decimal_repr (uintmax_t x, char *out, int repr_size)
     } while (x > 0);
 }
 
+int generate_decimal_repr_string (uintmax_t x, char *out)
+{
+    ASSERT(out)
+    
+    int repr_size = compute_decimal_repr_size(x);
+    generate_decimal_repr(x, out, repr_size);
+    out[repr_size] = '\0';
+    
+    return repr_size;
+}
+
 #endif