Anonymous avatar Anonymous committed 10d084f

Design: some error codes added

Comments (0)

Files changed (2)

 			case '{': case '[':
 				type = (*p == '{' ? JSON_OBJECT : JSON_ARRAY);
 				cur_token = jsmn_token_start(&params, type, p - js);
-				jsmn_assert(cur_token != NULL, -1);
+				jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
 				break;
 			case '}' : case ']':
 				type = (*p == '}' ? JSON_OBJECT : JSON_ARRAY);
 				cur_token = jsmn_token_end(&params, type, p - js + 1);
-				jsmn_assert(cur_token != NULL, -1);
+				jsmn_assert(cur_token != NULL, JSMN_ERROR_PART);
 				break;
 
 			case '-': case '0': case '1' : case '2': case '3' : case '4':
 			case '5': case '6': case '7' : case '8': case '9':
 				cur_token = jsmn_token_start(&params, JSON_NUMBER, p - js);
-				jsmn_assert(cur_token != NULL, -1);
+				jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
 				r = jsmn_parse_primitive(js, cur_token);
-				jsmn_assert(r == 0, -2);
+				jsmn_assert(r == 0, JSMN_ERROR_INVAL);
 				p = &js[cur_token->end] - 1;
 				break;
 			case 't': case 'f': case 'n' :
 				cur_token = jsmn_token_start(&params, JSON_OTHER, p - js);
-				jsmn_assert(cur_token != NULL, -1);
+				jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
 				r = jsmn_parse_primitive(js, cur_token);
-				jsmn_assert(r == 0, -2);
+				jsmn_assert(r == 0, JSMN_ERROR_INVAL);
 				p = &js[cur_token->end] - 1;
 				break;
 
 			case '\"':
 				cur_token = jsmn_token_start(&params, JSON_STRING, p - js);
-				jsmn_assert(cur_token != NULL, -1);
+				jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
 				r = jsmn_parse_string(js, cur_token);
-				jsmn_assert(r == 0, -2);
+				jsmn_assert(r == 0, JSMN_ERROR_INVAL);
 				p = &js[cur_token->end];
 				break;
 
 				break;
 
 			default:
-				jsmn_assert(0, -1); /* Assert always fails */
+				jsmn_return(JSMN_ERROR_INVAL); 
 		}
 		p++;
 	}
 	JSON_NUMBER
 } jsontype_t;
 
+typedef enum {
+	JSMN_ERROR_NOMEM = -1,
+	JSMN_ERROR_INVAL = -2,
+	JSMN_ERROR_PART = -3,
+	JSMN_SUCCESS = 0
+} jsmnerr_t;
+
 /**
  * JSON token description.
  * @param		type	type (object, array, string etc.)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.