Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1378)

Unified Diff: third_party/json_minify/minify-sans-regexp.js

Issue 9447090: Allow comments in extension config files. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed up license headers to pass license tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/json_minify/__init__.py ('k') | third_party/json_minify/minify_json.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/json_minify/minify-sans-regexp.js
diff --git a/third_party/json_minify/minify-sans-regexp.js b/third_party/json_minify/minify-sans-regexp.js
new file mode 100644
index 0000000000000000000000000000000000000000..99c817c2eb92ecb9044fb10cfdf3a4f8c152780b
--- /dev/null
+++ b/third_party/json_minify/minify-sans-regexp.js
@@ -0,0 +1,91 @@
+/*!
+ * `JSON.minify()`
+ * This version does not use regular expressions.
+ *
+ * Copyright 2011, Kyle Simpson.
+ * Copyright 2012, Kit Cambridge.
+ *
+ * Released under the MIT License.
+*/
+
+;(function () {
+ var JSON = this.JSON;
+
+ // Create the global JSON object if it doesn't exist.
+ if (Object(JSON) !== JSON) {
+ JSON = this.JSON = {};
+ }
+
+ JSON.minify = function (source) {
+ var index = 0, length = source.length, result = "", symbol, position;
+ while (index < length) {
+ symbol = source.charAt(index);
+ switch (symbol) {
+ // Ignore whitespace tokens. According to ES 5.1 section 15.12.1.1,
+ // whitespace tokens include tabs, carriage returns, line feeds, and
+ // space characters.
+ // -----------------------------------------------------------------
+ case "\t":
+ case "\r":
+ case "\n":
+ case " ":
+ index += 1;
+ break;
+ // Ignore line and block comments.
+ // -------------------------------
+ case "/":
+ symbol = source.charAt(index += 1);
+ switch (symbol) {
+ // Line comments.
+ // -------------
+ case "/":
+ position = source.indexOf("\n", index);
+ if (position < 0) {
+ // Check for CR-style line endings.
+ position = source.indexOf("\r", index);
+ }
+ index = position > -1 ? position : length;
+ break;
+ // Block comments.
+ // ---------------
+ case "*":
+ position = source.indexOf("*/", index);
+ if (position > -1) {
+ // Advance the scanner's position past the end of the comment.
+ index = position += 2;
+ break;
+ }
+ throw SyntaxError("Unterminated block comment.");
+ default:
+ throw SyntaxError("Invalid comment.");
+ }
+ break;
+ // Parse strings separately to ensure that any whitespace characters and
+ // JavaScript-style comments within them are preserved.
+ // ---------------------------------------------------------------------
+ case '"':
+ position = index;
+ while (index < length) {
+ symbol = source.charAt(index += 1);
+ if (symbol == "\\") {
+ // Skip past escaped characters.
+ index += 1;
+ } else if (symbol == '"') {
+ break;
+ }
+ }
+ if (source.charAt(index) == '"') {
+ result += source.slice(position, index += 1);
+ break;
+ }
+ throw SyntaxError("Unterminated string.");
+ // Preserve all other characters.
+ // ------------------------------
+ default:
+ result += symbol;
+ index += 1;
+ }
+ }
+ return result;
+ };
+}).call(this);
« no previous file with comments | « third_party/json_minify/__init__.py ('k') | third_party/json_minify/minify_json.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698