diff src/json.c @ 18800:f41b55f9357c v8.1.2388

patch 8.1.2388: using old C style comments Commit: https://github.com/vim/vim/commit/4ba37b5833de99db9e9afe8928b31c864182405c Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 4 21:57:43 2019 +0100 patch 8.1.2388: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Dec 2019 22:00:04 +0100
parents 0f7ae8010787
children ba9f50bfda83
line wrap: on
line diff
--- a/src/json.c
+++ b/src/json.c
@@ -48,7 +48,7 @@ json_encode(typval_T *val, int options)
 {
     garray_T ga;
 
-    /* Store bytes in the growarray. */
+    // Store bytes in the growarray.
     ga_init2(&ga, 1, 4000);
     json_encode_gap(&ga, val, options);
     ga_append(&ga, NUL);
@@ -104,8 +104,8 @@ write_string(garray_T *gap, char_u *str)
 
 	if (!enc_utf8)
 	{
-	    /* Convert the text from 'encoding' to utf-8, the JSON string is
-	     * always utf-8. */
+	    // Convert the text from 'encoding' to utf-8, the JSON string is
+	    // always utf-8.
 	    conv.vc_type = CONV_NONE;
 	    convert_setup(&conv, p_enc, (char_u*)"utf-8");
 	    if (conv.vc_type != CONV_NONE)
@@ -117,7 +117,7 @@ write_string(garray_T *gap, char_u *str)
 	while (*res != NUL)
 	{
 	    int c;
-	    /* always use utf-8 encoding, ignore 'encoding' */
+	    // always use utf-8 encoding, ignore 'encoding'
 	    c = utf_ptr2char(res);
 
 	    switch (c)
@@ -132,8 +132,8 @@ write_string(garray_T *gap, char_u *str)
 		    ga_append(gap, '\\'); ga_append(gap, 'f'); break;
 		case 0x0d:
 		    ga_append(gap, '\\'); ga_append(gap, 'r'); break;
-		case 0x22: /* " */
-		case 0x5c: /* \ */
+		case 0x22: // "
+		case 0x5c: // backslash
 		    ga_append(gap, '\\');
 		    ga_append(gap, c);
 		    break;
@@ -200,9 +200,9 @@ json_encode_item(garray_T *gap, typval_T
 		case VVAL_TRUE: ga_concat(gap, (char_u *)"true"); break;
 		case VVAL_NONE: if ((options & JSON_JS) != 0
 					     && (options & JSON_NO_NONE) == 0)
-				    /* empty item */
+				    // empty item
 				    break;
-				/* FALLTHROUGH */
+				// FALLTHROUGH
 		case VVAL_NULL: ga_concat(gap, (char_u *)"null"); break;
 	    }
 	    break;
@@ -222,7 +222,7 @@ json_encode_item(garray_T *gap, typval_T
 	case VAR_PARTIAL:
 	case VAR_JOB:
 	case VAR_CHANNEL:
-	    /* no JSON equivalent TODO: better error */
+	    // no JSON equivalent TODO: better error
 	    emsg(_(e_invarg));
 	    return FAIL;
 
@@ -268,7 +268,7 @@ json_encode_item(garray_T *gap, typval_T
 				&& li->li_next == NULL
 				&& li->li_tv.v_type == VAR_SPECIAL
 				&& li->li_tv.vval.v_number == VVAL_NONE)
-			    /* add an extra comma if the last item is v:none */
+			    // add an extra comma if the last item is v:none
 			    ga_append(gap, ',');
 			li = li->li_next;
 			if (li != NULL)
@@ -405,21 +405,21 @@ json_decode_string(js_read_T *reader, ty
     if (res != NULL)
 	ga_init2(&ga, 1, 200);
 
-    p = reader->js_buf + reader->js_used + 1; /* skip over " or ' */
+    p = reader->js_buf + reader->js_used + 1; // skip over " or '
     while (*p != quote)
     {
-	/* The JSON is always expected to be utf-8, thus use utf functions
-	 * here. The string is converted below if needed. */
+	// The JSON is always expected to be utf-8, thus use utf functions
+	// here. The string is converted below if needed.
 	if (*p == NUL || p[1] == NUL || utf_ptr2len(p) < utf_byte2len(*p))
 	{
-	    /* Not enough bytes to make a character or end of the string. Get
-	     * more if possible. */
+	    // Not enough bytes to make a character or end of the string. Get
+	    // more if possible.
 	    if (reader->js_fill == NULL)
 		break;
 	    len = (int)(reader->js_end - p);
 	    reader->js_used = (int)(p - reader->js_buf);
 	    if (!reader->js_fill(reader))
-		break; /* didn't get more */
+		break; // didn't get more
 	    p = reader->js_buf + reader->js_used;
 	    reader->js_end = reader->js_buf + STRLEN(reader->js_buf);
 	    continue;
@@ -466,7 +466,7 @@ json_decode_string(js_read_T *reader, ty
 		    {
 			varnumber_T	nr2 = 0;
 
-			/* decode surrogate pair: \ud812\u3456 */
+			// decode surrogate pair: \ud812\u3456
 			len = 0;
 			vim_str2nr(p + 2, NULL, &len,
 			     STR2NR_HEX + STR2NR_FORCE, &nr2, NULL, 4, TRUE);
@@ -492,7 +492,7 @@ json_decode_string(js_read_T *reader, ty
 		    }
 		    break;
 		default:
-		    /* not a special char, skip over \ */
+		    // not a special char, skip over backslash
 		    ++p;
 		    continue;
 	    }
@@ -533,7 +533,7 @@ json_decode_string(js_read_T *reader, ty
 	    {
 		vimconv_T   conv;
 
-		/* Convert the utf-8 string to 'encoding'. */
+		// Convert the utf-8 string to 'encoding'.
 		conv.vc_type = CONV_NONE;
 		convert_setup(&conv, (char_u*)"utf-8", p_enc);
 		if (conv.vc_type != CONV_NONE)
@@ -560,14 +560,14 @@ json_decode_string(js_read_T *reader, ty
 }
 
 typedef enum {
-    JSON_ARRAY,		/* parsing items in an array */
-    JSON_OBJECT_KEY,	/* parsing key of an object */
-    JSON_OBJECT		/* parsing item in an object, after the key */
+    JSON_ARRAY,		// parsing items in an array
+    JSON_OBJECT_KEY,	// parsing key of an object
+    JSON_OBJECT		// parsing item in an object, after the key
 } json_decode_T;
 
 typedef struct {
     json_decode_T jd_type;
-    typval_T	  jd_tv;	/* the list or dict */
+    typval_T	  jd_tv;	// the list or dict
     typval_T	  jd_key_tv;
     char_u	  *jd_key;
 } json_dec_item_T;
@@ -611,17 +611,17 @@ json_decode_item(js_read_T *reader, typv
 	    {
 		retval = MAYBE;
 		if (top_item->jd_type == JSON_OBJECT)
-		    /* did get the key, clear it */
+		    // did get the key, clear it
 		    clear_tv(&top_item->jd_key_tv);
 		goto theend;
 	    }
 	    if (top_item->jd_type == JSON_OBJECT_KEY
 					    || top_item->jd_type == JSON_ARRAY)
 	    {
-		/* Check for end of object or array. */
+		// Check for end of object or array.
 		if (*p == (top_item->jd_type == JSON_ARRAY ? ']' : '}'))
 		{
-		    ++reader->js_used; /* consume the ']' or '}' */
+		    ++reader->js_used; // consume the ']' or '}'
 		    --stack.ga_len;
 		    if (stack.ga_len == 0)
 		    {
@@ -644,7 +644,7 @@ json_decode_item(js_read_T *reader, typv
 	{
 	    char_u *key;
 
-	    /* accept an object key that is not in quotes */
+	    // accept an object key that is not in quotes
 	    key = p = reader->js_buf + reader->js_used;
 	    while (*p != NUL && *p != ':' && *p > ' ')
 		++p;
@@ -660,7 +660,7 @@ json_decode_item(js_read_T *reader, typv
 	{
 	    switch (*p)
 	    {
-		case '[': /* start of array */
+		case '[': // start of array
 		    if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
 		    {
 			retval = FAIL;
@@ -679,7 +679,7 @@ json_decode_item(js_read_T *reader, typv
 			break;
 		    }
 
-		    ++reader->js_used; /* consume the '[' */
+		    ++reader->js_used; // consume the '['
 		    top_item = ((json_dec_item_T *)stack.ga_data)
 								+ stack.ga_len;
 		    top_item->jd_type = JSON_ARRAY;
@@ -691,7 +691,7 @@ json_decode_item(js_read_T *reader, typv
 		    }
 		    continue;
 
-		case '{': /* start of object */
+		case '{': // start of object
 		    if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
 		    {
 			retval = FAIL;
@@ -710,7 +710,7 @@ json_decode_item(js_read_T *reader, typv
 			break;
 		    }
 
-		    ++reader->js_used; /* consume the '{' */
+		    ++reader->js_used; // consume the '{'
 		    top_item = ((json_dec_item_T *)stack.ga_data)
 								+ stack.ga_len;
 		    top_item->jd_type = JSON_OBJECT_KEY;
@@ -722,7 +722,7 @@ json_decode_item(js_read_T *reader, typv
 		    }
 		    continue;
 
-		case '"': /* string */
+		case '"': // string
 		    retval = json_decode_string(reader, cur_item, *p);
 		    break;
 
@@ -736,15 +736,15 @@ json_decode_item(js_read_T *reader, typv
 		    }
 		    break;
 
-		case ',': /* comma: empty item */
+		case ',': // comma: empty item
 		    if ((options & JSON_JS) == 0)
 		    {
 			emsg(_(e_invarg));
 			retval = FAIL;
 			break;
 		    }
-		    /* FALLTHROUGH */
-		case NUL: /* empty */
+		    // FALLTHROUGH
+		case NUL: // empty
 		    if (cur_item != NULL)
 		    {
 			cur_item->v_type = VAR_SPECIAL;
@@ -795,7 +795,7 @@ json_decode_item(js_read_T *reader, typv
 			    varnumber_T nr;
 
 			    vim_str2nr(reader->js_buf + reader->js_used,
-				    NULL, &len, 0, /* what */
+				    NULL, &len, 0, // what
 				    &nr, NULL, 0, TRUE);
 			    if (len == 0)
 			    {
@@ -881,7 +881,7 @@ json_decode_item(js_read_T *reader, typv
 			break;
 		    }
 #endif
-		    /* check for truncated name */
+		    // check for truncated name
 		    len = (int)(reader->js_end - (reader->js_buf + reader->js_used));
 		    if (
 			    (len < 5 && STRNICMP((char *)p, "false", len) == 0)
@@ -899,8 +899,8 @@ json_decode_item(js_read_T *reader, typv
 		    break;
 	    }
 
-	    /* We are finished when retval is FAIL or MAYBE and when at the
-	     * toplevel. */
+	    // We are finished when retval is FAIL or MAYBE and when at the
+	    // toplevel.
 	    if (retval == FAIL)
 		break;
 	    if (retval == MAYBE || stack.ga_len == 0)
@@ -1037,7 +1037,7 @@ item_end:
 	}
     }
 
-    /* Get here when parsing failed. */
+    // Get here when parsing failed.
     if (res != NULL)
     {
 	clear_tv(res);
@@ -1061,7 +1061,7 @@ json_decode_all(js_read_T *reader, typva
 {
     int ret;
 
-    /* We find the end once, to avoid calling strlen() many times. */
+    // We find the end once, to avoid calling strlen() many times.
     reader->js_end = reader->js_buf + STRLEN(reader->js_buf);
     json_skip_white(reader);
     ret = json_decode_item(reader, res, options);
@@ -1093,7 +1093,7 @@ json_decode(js_read_T *reader, typval_T 
 {
     int ret;
 
-    /* We find the end once, to avoid calling strlen() many times. */
+    // We find the end once, to avoid calling strlen() many times.
     reader->js_end = reader->js_buf + STRLEN(reader->js_buf);
     json_skip_white(reader);
     ret = json_decode_item(reader, res, options);
@@ -1119,7 +1119,7 @@ json_find_end(js_read_T *reader, int opt
     int used_save = reader->js_used;
     int ret;
 
-    /* We find the end once, to avoid calling strlen() many times. */
+    // We find the end once, to avoid calling strlen() many times.
     reader->js_end = reader->js_buf + STRLEN(reader->js_buf);
     json_skip_white(reader);
     ret = json_decode_item(reader, NULL, options);