diff --git a/CHANGELOG.md b/CHANGELOG.md index 109d4e1..1f9fca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +1.2312.0 +[Common] Fix regular expression format. +[Common] Change "ROOT" to "$" in JSON viewer. + +1.2311.0 +[Common] Fix "#" private class members format. + 1.2308.0 [NPP] Add ARM64 support. diff --git a/sub-proj/JSToolJS/CHANGELOG.md b/sub-proj/JSToolJS/CHANGELOG.md index fb3b043..c55fd8c 100644 --- a/sub-proj/JSToolJS/CHANGELOG.md +++ b/sub-proj/JSToolJS/CHANGELOG.md @@ -1,3 +1,10 @@ +1.2312.0 +[Common] Fix regular expression format. +[Common] Change "ROOT" to "$" in JSON viewer. + +1.2311.0 +[Common] Fix "#" private class members format. + 1.2308.0 [NPP] Add ARM64 support. diff --git a/sub-proj/JSToolJS/jsonpptreeview.js b/sub-proj/JSToolJS/jsonpptreeview.js index ff98e59..3d46b83 100644 --- a/sub-proj/JSToolJS/jsonpptreeview.js +++ b/sub-proj/JSToolJS/jsonpptreeview.js @@ -29,7 +29,7 @@ class JsonTreeProvider { * A implementation of TreeDataProvider */ constructor(rootJsonValue) { - this.rootNode = new JsonTreeNode("ROOT", rootJsonValue, 0); + this.rootNode = new JsonTreeNode("$", rootJsonValue, 0); } isRootNode(element) { diff --git a/sub-proj/JSToolJS/jsparser.js b/sub-proj/JSToolJS/jsparser.js index a555a3b..ed3bf7d 100644 --- a/sub-proj/JSToolJS/jsparser.js +++ b/sub-proj/JSToolJS/jsparser.js @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 'use strict'; -const VERSION = "1.2308.0.0"; +const VERSION = "1.2312.0.0"; function StringReplaceAll(string, target, replace) { return string.replace(new RegExp(target, 'g'), replace); @@ -146,7 +146,7 @@ class JSParser { // single operator return (ch == '.' || ch == '(' || ch == ')' || ch == '[' || ch == ']' || ch == '{' || ch == '}' || - ch == ',' || ch == ';' || ch == '~' || + ch == ',' || ch == ';' || ch == '~' || ch == '#' || ch == '\n'); } @@ -558,7 +558,8 @@ class JSParser { if (tokenBFirst == '/' && this.m_tokenB.type != COMMENT_TYPE_1 && this.m_tokenB.type != COMMENT_TYPE_2 && ((this.m_tokenA.type != STRING_TYPE && this.m_strBeforeReg.indexOf(tokenALast) != -1) || - (this.m_tokenA.code == "return" || this.m_tokenA.code == "throw"))) { + (this.m_tokenA.code == "return" || this.m_tokenA.code == "throw" || + this.m_tokenA.code == "in" || this.m_tokenA.code == "of"))) { this.m_bRegular = true; this.GetTokenRaw(); // put regular into m_tokenB } diff --git a/sub-proj/JSToolJS/package-lock.json b/sub-proj/JSToolJS/package-lock.json index 30135f8..bcaa9a1 100644 --- a/sub-proj/JSToolJS/package-lock.json +++ b/sub-proj/JSToolJS/package-lock.json @@ -1,12 +1,12 @@ { "name": "jstool", - "version": "1.2308.0", + "version": "1.2312.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "jstool", - "version": "1.2308.0", + "version": "1.2312.0", "license": "GPL-2.0", "devDependencies": { "@types/node": "^14.0.0", diff --git a/sub-proj/JSToolJS/package.json b/sub-proj/JSToolJS/package.json index 4ded3b8..95544df 100644 --- a/sub-proj/JSToolJS/package.json +++ b/sub-proj/JSToolJS/package.json @@ -2,7 +2,7 @@ "name": "jstool", "displayName": "JSTool", "description": "JS (JSON) Tool for VSC", - "version": "1.2308.0", + "version": "1.2312.0", "publisher": "sunjw", "license": "GPL-2.0", "engines": { diff --git a/sub-proj/JSToolJS/realjsformatter.js b/sub-proj/JSToolJS/realjsformatter.js index 48315e1..cb26315 100644 --- a/sub-proj/JSToolJS/realjsformatter.js +++ b/sub-proj/JSToolJS/realjsformatter.js @@ -227,7 +227,12 @@ class RealJSFormatter extends JSParser.JSParser { //PutToken(m_tokenA); switch (this.m_tokenA.type) { case JSParser.REGULAR_TYPE: - this.PutToken(this.m_tokenA); // directly output regular without any format + if (this.m_tokenPreA.type == JSParser.STRING_TYPE && + !this.m_bracketKeywordSet.includes(this.m_tokenPreA.code)) { + this.PutToken(this.m_tokenA, " "); + } else { + this.PutToken(this.m_tokenA); // directly output regular without any format + } break; case JSParser.COMMENT_TYPE_1: case JSParser.COMMENT_TYPE_2: @@ -353,7 +358,8 @@ class RealJSFormatter extends JSParser.JSParser { if (this.m_tokenA.code == "(" || this.m_tokenA.code == ")" || this.m_tokenA.code == "[" || this.m_tokenA.code == "]" || this.m_tokenA.code == "!" || this.m_tokenA.code == "!!" || - this.m_tokenA.code == "~" || this.m_tokenA.code == ".") { + this.m_tokenA.code == "~" || this.m_tokenA.code == "." || + this.m_tokenA.code == "#") { // ()[]!. with no format if ((this.m_tokenA.code == ")" || this.m_tokenA.code == "]") && (topStack == JSParser.JS_ASSIGN || topStack == JSParser.JS_HELPER)) { @@ -795,7 +801,7 @@ class RealJSFormatter extends JSParser.JSParser { if (this.m_tokenB.type == JSParser.STRING_TYPE || this.m_tokenB.type == JSParser.COMMENT_TYPE_1 || this.m_tokenB.type == JSParser.COMMENT_TYPE_2 || - this.m_tokenB.code == "{" || + this.m_tokenB.code == "{" || this.m_tokenB.code == "#" || (this.m_declareKeywordSet.includes(this.m_tokenA.code) && this.m_tokenB.code == "[")) { if (this.m_tokenA.type == JSParser.STRING_TYPE && this.m_tokenA.code.endsWith("${")) { @@ -831,7 +837,6 @@ class RealJSFormatter extends JSParser.JSParser { // indent after read () this.m_brcNeedStack.push(false); this.m_blockStack.push(this.m_blockMap[this.m_tokenA.code]); - } if (!bTokenAPropName && this.m_tokenA.code == "switch") { diff --git a/sub-proj/JSToolSite/inc/version.ini b/sub-proj/JSToolSite/inc/version.ini index 2b61512..2a03bb5 100644 --- a/sub-proj/JSToolSite/inc/version.ini +++ b/sub-proj/JSToolSite/inc/version.ini @@ -1,4 +1,4 @@ [JSMinNpp] name=JSToolNpp.zip -version=1.2308.0 +version=1.2312.0 url=download.php diff --git a/sub-proj/JSToolSite/npp/index.php b/sub-proj/JSToolSite/npp/index.php index 2acf35e..0431f39 100644 --- a/sub-proj/JSToolSite/npp/index.php +++ b/sub-proj/JSToolSite/npp/index.php @@ -100,7 +100,8 @@

 

What's New in :

 

Buy Me a Coffee at ko-fi.com

diff --git a/sub-proj/JSToolSite/vsc/index.php b/sub-proj/JSToolSite/vsc/index.php index 10ddcff..79739b4 100644 --- a/sub-proj/JSToolSite/vsc/index.php +++ b/sub-proj/JSToolSite/vsc/index.php @@ -44,7 +44,8 @@

 

What's New in :

 

Buy Me a Coffee at ko-fi.com

diff --git a/sub-proj/Test/jsformat/privateclass.js b/sub-proj/Test/jsformat/privateclass.js new file mode 100644 index 0000000..8638427 --- /dev/null +++ b/sub-proj/Test/jsformat/privateclass.js @@ -0,0 +1,106 @@ +class ClassWithPrivateField { + #privateField; + + constructor() { + this.#privateField = 42; + } +} + +class Subclass extends ClassWithPrivateField { + #subPrivateField; + + constructor() { + super(); + this.#subPrivateField = 23; + } +} + +new Subclass(); // In some dev tools, it shows Subclass {#privateField: 42, #subPrivateField: 23} + + +class ClassWithPrivateField { + #privateField; + + constructor() { + delete this.#privateField; // Syntax error + this.#undeclaredField = 42; // Syntax error + } +} + +const instance = new ClassWithPrivateField(); +instance.#privateField; // Syntax error + +class C { + #x; + constructor(x) { + this.#x = x; + } + static getX(obj) { + if (#x in obj) return obj.#x; + + return "obj must be an instance of C"; + } +} +console.log(C.getX(new C("foo"))); // "foo" +console.log(C.getX(new C(0.196))); // 0.196 +console.log(C.getX(new C(new Date()))); // the current date and time +console.log(C.getX({})); // "obj must be an instance of C" + +class Stamper extends class { + // A base class whose constructor returns the object it's given + constructor(obj) { + return obj; + } +} { + // This declaration will "stamp" the private field onto the object + // returned by the base class constructor + #stamp = 42; + static getStamp(obj) { + return obj.#stamp; + } +} + +const obj = {}; +new Stamper(obj); +// `Stamper` calls `Base`, which returns `obj`, so `obj` is +// now the `this` value. `Stamper` then defines `#stamp` on `obj` + +console.log(obj); // In some dev tools, it shows {#stamp: 42} +console.log(Stamper.getStamp(obj)); // 42 +console.log(obj instanceof Stamper); // false + +// You cannot stamp private properties twice +new Stamper(obj); // Error: Initializing an object twice is an error with private fields + +class ClassWithPrivateAccessor { + #message; + + get #decoratedMessage() { + return `馃幀${this.#message}馃洃`; + } + set #decoratedMessage(msg) { + this.#message = msg; + } + + constructor() { + this.#decoratedMessage = "hello world"; + console.log(this.#decoratedMessage); + } +} + +new ClassWithPrivateAccessor(); // 馃幀hello world馃洃 + +class ClassWithPrivateStaticMethod { + static #isInternalConstructing = false; + static #privateStaticMethod() { + return 42; + } + + static publicStaticMethod() { + return this.#privateStaticMethod(); + } +} + +class Subclass extends ClassWithPrivateStaticMethod {} + +console.log(Subclass.publicStaticMethod()); // TypeError: Cannot read private member #privateStaticMethod from an object whose class did not declare it diff --git a/sub-proj/Test/jsformat/privateclass.test.js b/sub-proj/Test/jsformat/privateclass.test.js new file mode 100644 index 0000000..b9671ad --- /dev/null +++ b/sub-proj/Test/jsformat/privateclass.test.js @@ -0,0 +1,107 @@ +class ClassWithPrivateField { + #privateField; + + constructor() { + this.#privateField = 42; + } +} + +class Subclass extends ClassWithPrivateField { + #subPrivateField; + + constructor() { + super(); + this.#subPrivateField = 23; + } +} + +new Subclass(); // In some dev tools, it shows Subclass {#privateField: 42, #subPrivateField: 23} + + +class ClassWithPrivateField { + #privateField; + + constructor() { + delete this.#privateField; // Syntax error + this.#undeclaredField = 42; // Syntax error + } +} + +const instance = new ClassWithPrivateField(); +instance.#privateField; // Syntax error + +class C { + #x; + constructor(x) { + this.#x = x; + } + static getX(obj) { + if (#x in obj) + return obj.#x; + + return "obj must be an instance of C"; + } +} +console.log(C.getX(new C("foo"))); // "foo" +console.log(C.getX(new C(0.196))); // 0.196 +console.log(C.getX(new C(new Date()))); // the current date and time +console.log(C.getX({})); // "obj must be an instance of C" + +class Stamper extends class { + // A base class whose constructor returns the object it's given + constructor(obj) { + return obj; + } +} { + // This declaration will "stamp" the private field onto the object + // returned by the base class constructor + #stamp = 42; + static getStamp(obj) { + return obj.#stamp; + } +} + +const obj = {}; +new Stamper(obj); +// `Stamper` calls `Base`, which returns `obj`, so `obj` is +// now the `this` value. `Stamper` then defines `#stamp` on `obj` + +console.log(obj); // In some dev tools, it shows {#stamp: 42} +console.log(Stamper.getStamp(obj)); // 42 +console.log(obj instanceof Stamper); // false + +// You cannot stamp private properties twice +new Stamper(obj); // Error: Initializing an object twice is an error with private fields + +class ClassWithPrivateAccessor { + #message; + + get #decoratedMessage() { + return `馃幀${this.#message}馃洃`; + } + set #decoratedMessage(msg) { + this.#message = msg; + } + + constructor() { + this.#decoratedMessage = "hello world"; + console.log(this.#decoratedMessage); + } +} + +new ClassWithPrivateAccessor(); // 馃幀hello world馃洃 + +class ClassWithPrivateStaticMethod { + static #isInternalConstructing = false; + static #privateStaticMethod() { + return 42; + } + + static publicStaticMethod() { + return this.#privateStaticMethod(); + } +} + +class Subclass extends ClassWithPrivateStaticMethod {} + +console.log(Subclass.publicStaticMethod()); // TypeError: Cannot read private member #privateStaticMethod from an object whose class did not declare it diff --git a/sub-proj/Test/jsformat/reg6.js b/sub-proj/Test/jsformat/reg6.js new file mode 100644 index 0000000..6039c29 --- /dev/null +++ b/sub-proj/Test/jsformat/reg6.js @@ -0,0 +1,2 @@ +webpackJsonp([0],{"0xDb":function(t,i,e){"use strict";i.a=function(t,i){if(t){var e=new Date(t),n={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(var c in/(y+)/.test(i)&&(i=i.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+c+")").test(i)&&(i=i.replace(RegExp.$1,1===RegExp.$1.length?n[c]:("00"+n[c]).substr((""+n[c]).length)));return i}return""}}}); +webpackJsonp([0],{"0xDb":function(t,i,e){"use strict";i.a=function(t,i){if(t){var e=new Date(t),n={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(var c of/(y+)/.test(i)&&(i=i.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+c+")").test(i)&&(i=i.replace(RegExp.$1,1===RegExp.$1.length?n[c]:("00"+n[c]).substr((""+n[c]).length)));return i}return""}}}); diff --git a/sub-proj/Test/jsformat/reg6.test.js b/sub-proj/Test/jsformat/reg6.test.js new file mode 100644 index 0000000..722387d --- /dev/null +++ b/sub-proj/Test/jsformat/reg6.test.js @@ -0,0 +1,46 @@ +webpackJsonp([0], { + "0xDb": function (t, i, e) { + "use strict"; + i.a = function (t, i) { + if (t) { + var e = new Date(t), + n = { + "M+": e.getMonth() + 1, + "d+": e.getDate(), + "H+": e.getHours(), + "m+": e.getMinutes(), + "s+": e.getSeconds(), + "q+": Math.floor((e.getMonth() + 3) / 3), + S: e.getMilliseconds() + }; + for (var c in /(y+)/.test(i) && (i = i.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length))), n) + new RegExp("(" + c + ")").test(i) && (i = i.replace(RegExp.$1, 1 === RegExp.$1.length ? n[c] : ("00" + n[c]).substr(("" + n[c]).length))); + return i + } + return "" + } + } +}); +webpackJsonp([0], { + "0xDb": function (t, i, e) { + "use strict"; + i.a = function (t, i) { + if (t) { + var e = new Date(t), + n = { + "M+": e.getMonth() + 1, + "d+": e.getDate(), + "H+": e.getHours(), + "m+": e.getMinutes(), + "s+": e.getSeconds(), + "q+": Math.floor((e.getMonth() + 3) / 3), + S: e.getMilliseconds() + }; + for (var c of /(y+)/.test(i) && (i = i.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length))), n) + new RegExp("(" + c + ")").test(i) && (i = i.replace(RegExp.$1, 1 === RegExp.$1.length ? n[c] : ("00" + n[c]).substr(("" + n[c]).length))); + return i + } + return "" + } + } +}); diff --git a/sub-proj/Test/jsformattest.py b/sub-proj/Test/jsformattest.py index 86fc038..a14dd56 100644 --- a/sub-proj/Test/jsformattest.py +++ b/sub-proj/Test/jsformattest.py @@ -112,9 +112,6 @@ def main(): comm_util.log_print('Unknown operating system.') return else: - if win_arm64: - comm_util.log_print('Windows ARM64 not support Node.') - return if not comm_util.is_windows() and not comm_util.is_macos() and not comm_util.is_linux(): comm_util.log_print('Unknown operating system.') return @@ -143,6 +140,8 @@ def main(): if validate: # validate test only support Windows x64 relase build jsformatter_path_sel = JSFORMATTER_REL_PATH_WIN_64 + if win_arm64: + jsformatter_path_sel = JSFORMATTER_REL_PATH_WIN_ARM64 if nodejs or validate: jsformatter_nodejs_script_sel = JSFORMATTER_NODEJS_SCRIPT_PATH @@ -153,8 +152,8 @@ def main(): if nodejs: case_runtime = NodeCaseRuntime(jsformatter_nodejs_script_sel) if validate: - if comm_util.is_macos() or win_arm64: - comm_util.log_print('Validate only support Windows x64.') + if comm_util.is_macos(): + comm_util.log_print('Validate only support Windows.') return case_runtime = ValidateCaseRuntime(jsformatter_path_sel, jsformatter_nodejs_script_sel) diff --git a/sub-proj/Test/jsonpptest.py b/sub-proj/Test/jsonpptest.py index 1abee29..6addb90 100644 --- a/sub-proj/Test/jsonpptest.py +++ b/sub-proj/Test/jsonpptest.py @@ -105,9 +105,6 @@ def main(): if not nodejs and not comm_util.is_windows(): comm_util.log_print('JsonPP native test only supports Windows.') return - if nodejs and win_arm64: - comm_util.log_print('JsonPP node test only supports Windows x64.') - return # prepare path jsonpp_path_sel = '' diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2311.0.src.zip b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.src.zip new file mode 100644 index 0000000..017c29c Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.src.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.32.zip b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.32.zip new file mode 100644 index 0000000..3b00a5e Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.32.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.64.zip b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.64.zip new file mode 100644 index 0000000..0c5d6de Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.64.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.arm64.zip b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.arm64.zip new file mode 100644 index 0000000..782a2df Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2311.0.uni.arm64.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2312.0.src.zip b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.src.zip new file mode 100644 index 0000000..67b4003 Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.src.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.32.zip b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.32.zip new file mode 100644 index 0000000..57710c5 Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.32.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.64.zip b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.64.zip new file mode 100644 index 0000000..bef1def Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.64.zip differ diff --git a/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.arm64.zip b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.arm64.zip new file mode 100644 index 0000000..e1af2a1 Binary files /dev/null and b/trunk/ReleasedFiles/JSToolNPP.1.2312.0.uni.arm64.zip differ diff --git a/trunk/ReleasedFiles/ReleaseVersion.json b/trunk/ReleasedFiles/ReleaseVersion.json index e5b8858..c2812a4 100644 --- a/trunk/ReleasedFiles/ReleaseVersion.json +++ b/trunk/ReleasedFiles/ReleaseVersion.json @@ -1,3 +1,3 @@ { - "CurrentVersion": "1.2308.0.0" + "CurrentVersion": "1.2312.0.0" } diff --git a/trunk/ReleasedFiles/sunjw.jstool-1.2311.0.vsix b/trunk/ReleasedFiles/sunjw.jstool-1.2311.0.vsix new file mode 100644 index 0000000..482dd5d Binary files /dev/null and b/trunk/ReleasedFiles/sunjw.jstool-1.2311.0.vsix differ diff --git a/trunk/ReleasedFiles/sunjw.jstool-1.2312.0.vsix b/trunk/ReleasedFiles/sunjw.jstool-1.2312.0.vsix new file mode 100644 index 0000000..423ebeb Binary files /dev/null and b/trunk/ReleasedFiles/sunjw.jstool-1.2312.0.vsix differ diff --git a/trunk/src/JSONDialog.cpp b/trunk/src/JSONDialog.cpp index ce69748..9af1874 100644 --- a/trunk/src/JSONDialog.cpp +++ b/trunk/src/JSONDialog.cpp @@ -231,7 +231,7 @@ HTREEITEM JSONDialog::initTree() TreeView_DeleteAllItems(GetDlgItem(m_hDlg, IDC_TREE_JSON)); } - HTREEITEM root = insertTree(TEXT("ROOT"), -1, TVI_ROOT); + HTREEITEM root = insertTree(TEXT(JSON_TREE_ROOT), -1, TVI_ROOT); return root; } diff --git a/trunk/src/JsonTree.cpp b/trunk/src/JsonTree.cpp index 8a008fb..90359d7 100644 --- a/trunk/src/JsonTree.cpp +++ b/trunk/src/JsonTree.cpp @@ -96,9 +96,9 @@ tstring JsonTree::getJsonNodePath(HTREEITEM hti) } else { - if (tstrTreeText == TEXT("ROOT")) + if (tstrTreeText == TEXT(JSON_TREE_ROOT)) { - tstrKey = TEXT("ROOT"); + tstrKey = TEXT(JSON_TREE_ROOT); } if (tstrJsonPath[0] == TEXT('[')) diff --git a/trunk/src/JsonTree.h b/trunk/src/JsonTree.h index 9d1c9f6..eb67fde 100644 --- a/trunk/src/JsonTree.h +++ b/trunk/src/JsonTree.h @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "PluginInterface.h" #include "TreeViewController.h" +#define JSON_TREE_ROOT "$" #define JSON_TREE_SPLITOR ": " class JsonTree: public TreeViewController diff --git a/trunk/src/jsparser.cpp b/trunk/src/jsparser.cpp index b7f92c0..c53c682 100644 --- a/trunk/src/jsparser.cpp +++ b/trunk/src/jsparser.cpp @@ -515,7 +515,8 @@ void JSParser::PrepareRegular() if (tokenBFirst == '/' && m_tokenB.type != COMMENT_TYPE_1 && m_tokenB.type != COMMENT_TYPE_2 && ((m_tokenA.type != STRING_TYPE && m_strBeforeReg.find(tokenALast) != string::npos) || - (m_tokenA.code == "return" || m_tokenA.code == "throw"))) + (m_tokenA.code == "return" || m_tokenA.code == "throw" || + m_tokenA.code == "in" || m_tokenA.code == "of"))) { m_bRegular = true; GetTokenRaw(); // 把正则内容加到 m_tokenB diff --git a/trunk/src/jsparser.h b/trunk/src/jsparser.h index 2090f1b..4185bf9 100644 --- a/trunk/src/jsparser.h +++ b/trunk/src/jsparser.h @@ -162,7 +162,7 @@ class JSParser // 单字符符号 return (ch == '.' || ch == '(' || ch == ')' || ch == '[' || ch == ']' || ch == '{' || ch == '}' || - ch == ',' || ch == ';' || ch == '~' || + ch == ',' || ch == ';' || ch == '~' || ch == '#' || ch == '\n'); } diff --git a/trunk/src/realjsformatter.cpp b/trunk/src/realjsformatter.cpp index 4ab37e8..6e17683 100644 --- a/trunk/src/realjsformatter.cpp +++ b/trunk/src/realjsformatter.cpp @@ -442,7 +442,15 @@ void RealJSFormatter::Go() switch (m_tokenA.type) { case REGULAR_TYPE: - PutToken(m_tokenA); // 正则表达式直接输出, 前后没有任何样式 + if (m_tokenPreA.type == STRING_TYPE && + m_bracketKeywordSet.find(m_tokenPreA.code) == m_bracketKeywordSet.end()) + { + PutToken(m_tokenA, string(" ")); + } + else + { + PutToken(m_tokenA); // 正则表达式直接输出, 前后没有任何样式 + } break; case COMMENT_TYPE_1: case COMMENT_TYPE_2: @@ -517,7 +525,8 @@ void RealJSFormatter::ProcessOper(bool bHaveNewLine, char tokenAFirst, char toke if (m_tokenA.code == "(" || m_tokenA.code == ")" || m_tokenA.code == "[" || m_tokenA.code == "]" || m_tokenA.code == "!" || m_tokenA.code == "!!" || - m_tokenA.code == "~" || m_tokenA.code == ".") + m_tokenA.code == "~" || m_tokenA.code == "." || + m_tokenA.code == "#") { // ()[]!. 都是前后没有样式的运算符 if ((m_tokenA.code == ")" || m_tokenA.code == "]") && @@ -1057,7 +1066,7 @@ void RealJSFormatter::ProcessString(bool bHaveNewLine, char tokenAFirst, char to if (m_tokenB.type == STRING_TYPE || m_tokenB.type == COMMENT_TYPE_1 || m_tokenB.type == COMMENT_TYPE_2 || - m_tokenB.code == "{" || + m_tokenB.code == "{" || m_tokenB.code == "#" || (m_declareKeywordSet.find(m_tokenA.code) != m_declareKeywordSet.end() && m_tokenB.code == "[")) { @@ -1106,7 +1115,6 @@ void RealJSFormatter::ProcessString(bool bHaveNewLine, char tokenAFirst, char to // 等待 (), () 到来后才能加缩进 m_brcNeedStack.push(false); m_blockStack.push(m_blockMap[m_tokenA.code]); - } if (!bTokenAPropName && m_tokenA.code == "switch") diff --git a/trunk/src/strhelper.cpp b/trunk/src/strhelper.cpp index 2643312..ab7379a 100644 --- a/trunk/src/strhelper.cpp +++ b/trunk/src/strhelper.cpp @@ -1,7 +1,7 @@ /* * strhelper implementation file * Author: Sun Junwen - * Version: 2.2.1 + * Version: 2.2.2 * Provides converting from tstring, string and wstring to each other * And provides string's utf8 converting. * Provides triming function to string and wstring. @@ -35,7 +35,7 @@ namespace sunjwbase // Windows convert static std::string _wstrtostr(const std::wstring& wstr, UINT codePage) { - // Convert a wstring to a specified code page encoded string + // Convert a wstring to a specified code page encoded string size_t strLen = WideCharToMultiByte(codePage, 0, wstr.c_str(), (int)wstr.length(), NULL, 0, NULL, NULL); std::string strTo; char *szTo = new char[strLen + 1]; @@ -45,10 +45,10 @@ namespace sunjwbase delete[] szTo; return strTo; } - + static std::wstring _strtowstr(const std::string& str, UINT codePage) { - // Convert a specified code page encoded string to a wstring + // Convert a specified code page encoded string to a wstring size_t wstrLen = MultiByteToWideChar(codePage, 0, str.c_str(), -1, NULL, 0); std::wstring wstrTo; wchar_t *wszTo = new wchar_t[wstrLen + 1]; @@ -71,27 +71,27 @@ std::string sunjwbase::striconv(const std::string& input, size_t outleft = inleft * 4 + 1; // should be large enough char* outptr = new char[outleft]; bzero(outptr, outleft); - + strcpy(inptr, input.c_str()); - + iconv_t cd; // conversion descriptor if ((cd = iconv_open(to_code.c_str(), from_code.c_str())) == (iconv_t) (-1)) { iconv_close(cd); // failed clean return input; } - + char* in = inptr; char* out = outptr; outleft = iconv(cd, &in, &inleft, &out, &outleft); - + iconv_close(cd); - + std::string strRet(outptr); - + delete[] inptr; delete[] outptr; - + return strRet; } #endif @@ -141,7 +141,7 @@ std::string sunjwbase::wstrtostr(const std::wstring& wstr) std::string str(char_buf); delete[] char_buf; setlocale(LC_ALL, "C"); - + return str; #endif } @@ -161,7 +161,7 @@ std::wstring sunjwbase::strtowstr(const std::string& str) std::wstring wstr(wct_buf, num_chars); delete[] wct_buf; setlocale(LC_ALL, "C"); - + return wstr; #endif } @@ -181,7 +181,7 @@ std::string sunjwbase::asciiconvjson(std::string& strJsonUtf16) n[1] = strJsonUtf16[i + 3]; n[2] = strJsonUtf16[i + 4]; n[3] = strJsonUtf16[i + 5]; - + i += 5; int utf16 = 0; @@ -260,7 +260,7 @@ std::string sunjwbase::strreplace(const std::string& base, const std::string& sr ret.replace(pos, srcLen, des); pos = ret.find(src, pos + desLen); } - + return ret; } @@ -276,7 +276,7 @@ std::wstring sunjwbase::strreplace(const std::wstring& base, const std::wstring& ret.replace(pos, srcLen, des); pos = ret.find(src, pos + desLen); } - + return ret; } @@ -347,7 +347,7 @@ std::string sunjwbase::itostr(int num, int idx /* = 10 */) break; } } - + return ret; } @@ -361,45 +361,36 @@ std::string sunjwbase::strappendformat(std::string& str, const char *format, ... temp.resize(size); va_start(vl, format); #if defined (WIN32) - int n = vsnprintf_s((char *)temp.c_str(), size, size, format, vl); + int n = vsnprintf_s((char *)temp.data(), size, _TRUNCATE, format, vl); #else - int n = vsnprintf((char *)temp.c_str(), size, format, vl); + int n = vsnprintf((char *)temp.data(), size, format, vl); #endif va_end(vl); - if (n > -1 && n < size) - { - temp.resize(n); + if (n > -1 && n < size) { + // temp.resize(n); break; } if (n > -1) - { size = n + 1; // not large enough - } else - { size *= 2; - } } - str.append(temp); - + str.append(temp.c_str()); + return str; } bool sunjwbase::str_startwith(const std::string& str, const std::string& target) { if (str.length() < target.length()) - { return false; - } // Length is enough, let's check content. size_t i = 0; for (; i < target.length(); ++i) { if (str[i] != target[i]) - { return false; - } } return (i == target.length()); @@ -408,9 +399,7 @@ bool sunjwbase::str_startwith(const std::string& str, const std::string& target) bool sunjwbase::str_endwith(const std::string& str, const std::string& target) { if (str.length() < target.length()) - { return false; - } // Length is enough, let's check content. size_t str_len = str.length(); @@ -419,9 +408,7 @@ bool sunjwbase::str_endwith(const std::string& str, const std::string& target) for (; i < target.length(); ++i) { if (str[str_len - target_len + i] != target[i]) - { return false; - } } return (i == target.length()); diff --git a/trunk/src/strhelper.h b/trunk/src/strhelper.h index 17cd624..046eb20 100644 --- a/trunk/src/strhelper.h +++ b/trunk/src/strhelper.h @@ -1,7 +1,7 @@ /* * strhelper header file * Author: Sun Junwen - * Version: 2.2.1 + * Version: 2.2.2 * Provides converting from tstring, string and wstring to each other * And provides string's utf8 converting. * Provides triming function to string and wstring. @@ -23,7 +23,7 @@ namespace sunjwbase #else typedef std::string tstring; #endif - + #if defined (WIN32) typedef __int64 INT64; #endif @@ -44,10 +44,10 @@ namespace sunjwbase * 2nd, call strtowstr */ std::wstring strtowstrutf8(const std::string& str); - + std::string wstrtostr(const std::wstring& wstr); std::wstring strtowstr(const std::string& str); - + #if defined (__APPLE__) || defined (__unix) std::string striconv(const std::string& input, const std::string& to_code, @@ -80,7 +80,7 @@ namespace sunjwbase // convert JSON utf16 encoded string to native encoded string std::string asciiconvjson(std::string& strJsonUtf16); - + inline std::string tstrtostr(const tstring& tstr) { #if defined(_UNICODE_HELPER) @@ -89,7 +89,7 @@ namespace sunjwbase return tstr; #endif } - + inline std::wstring tstrtowstr(const tstring& tstr) { #if defined(_UNICODE_HELPER) @@ -174,7 +174,7 @@ namespace sunjwbase { strequal_ci( const std::locale& loc ):m_loc(loc) {} - + bool operator()(charT ch1, charT ch2) { return std::toupper(ch1, m_loc) == std::toupper(ch2, m_loc); @@ -200,7 +200,7 @@ namespace sunjwbase return -1; // not found } } - + // itostr std::string itostr(int num, int idx = 10); @@ -213,5 +213,4 @@ namespace sunjwbase } - #endif diff --git a/trunk/src/version.h b/trunk/src/version.h index 9d59cc4..92f5d25 100644 --- a/trunk/src/version.h +++ b/trunk/src/version.h @@ -1,2 +1,2 @@ -#define VERSION_VALUE "1.2308.0.0" -#define VERSION_DIGITALVALUE 1, 2308, 0, 0 +#define VERSION_VALUE "1.2312.0.0" +#define VERSION_DIGITALVALUE 1, 2312, 0, 0