From 56ab9590b2893314435098c924cef52b91b2d564 Mon Sep 17 00:00:00 2001 From: sergeyshushlyapin Date: Thu, 30 Apr 2015 02:01:54 +0300 Subject: [PATCH 1/4] Fix abbreviation parsing in folder names (#192) --- src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js index 8a641be6e..837122915 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js @@ -6,8 +6,8 @@ return this.replace(/^\s+|\s+$/g, ''); } } - - return unformattedString.replace(/([A-Z])/g, " $1").trim(); + + return unformattedString.replace(/([A-Z][a-z])/g, " $1").replace(/([A-Z]([A-Z])*)/g, " $1").trim(); } function removeBeginningHash(hashedString) { From a0c16a8f7f796970514dce82b1a4c165af1a032d Mon Sep 17 00:00:00 2001 From: sergeyshushlyapin Date: Mon, 4 May 2015 04:38:49 +0300 Subject: [PATCH 2/4] Add JS unit test and fix regular expression to distinguish abbreviations (#192) --- src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js | 8 ++++++-- src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js index 837122915..12497af9c 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js @@ -6,8 +6,12 @@ return this.replace(/^\s+|\s+$/g, ''); } } - - return unformattedString.replace(/([A-Z][a-z])/g, " $1").replace(/([A-Z]([A-Z])*)/g, " $1").trim(); + + return unformattedString + .replace(/([A-Z][^A-Z+])/g, " $1") + .replace(/([A-Z][^a-z+])/g, " $1") + .replace(/\s\s/g, '') + .trim(); } function removeBeginningHash(hashedString) { diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js index 9f122e406..f7278c125 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js @@ -1,7 +1,8 @@ test("Can convert camel cased string to spaced string", function () { equal(addSpacesToCamelCasedString("ThisIsATestString"), "This Is A Test String", "Happy path test"); equal(addSpacesToCamelCasedString("00ThisIsATestString"), "00 This Is A Test String", "String prefaced by numbers"); - equal(addSpacesToCamelCasedString("ThisIsATestString."), "This Is A Test String.", "String ending with puncuation."); + equal(addSpacesToCamelCasedString("ThisIsATestString."), "This Is A Test String.", "String ending with punctuation."); + equal(addSpacesToCamelCasedString("ThisIsATestStringABC"), "This Is A Test String ABC", "String with abbreviation."); }); test("Can pull off # from hashtag", function() { From 45b82b54905f664d059a0fac699016c711c0e735 Mon Sep 17 00:00:00 2001 From: sergeyshushlyapin Date: Mon, 4 May 2015 05:15:20 +0300 Subject: [PATCH 3/4] Add JS unit test to check if can parse a title with an abbreviation at the beginning (#192) --- src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js index f7278c125..e03d40259 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js @@ -2,7 +2,8 @@ equal(addSpacesToCamelCasedString("ThisIsATestString"), "This Is A Test String", "Happy path test"); equal(addSpacesToCamelCasedString("00ThisIsATestString"), "00 This Is A Test String", "String prefaced by numbers"); equal(addSpacesToCamelCasedString("ThisIsATestString."), "This Is A Test String.", "String ending with punctuation."); - equal(addSpacesToCamelCasedString("ThisIsATestStringABC"), "This Is A Test String ABC", "String with abbreviation."); + equal(addSpacesToCamelCasedString("ThisIsATestStringABC"), "This Is A Test String ABC", "String with abbreviation at the end."); + equal(addSpacesToCamelCasedString("ABCThisIsATestString"), "ABC This Is A Test String", "String with abbreviation at the beginning."); }); test("Can pull off # from hashtag", function() { From a5193627036866ce0db47cd71d0b7c58f98090a5 Mon Sep 17 00:00:00 2001 From: sergeyshushlyapin Date: Sat, 9 May 2015 14:41:18 +0300 Subject: [PATCH 4/4] Replace regex with a while loop. Fix splitting 3 characters abbreviations at the beginning of a phrase --- .../js/stringFormatting.js | 26 ++++++++++++++----- .../Pickles.BaseDhtmlFiles/tests/tests.js | 5 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js index 12497af9c..da4267467 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js @@ -2,16 +2,28 @@ // IE does not implement trim() and the following replaces the functionality if unavailable // http://stackoverflow.com/questions/2308134/trim-in-javascript-not-working-in-ie if (typeof String.prototype.trim !== 'function') { - String.prototype.trim = function() { + String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); } } - - return unformattedString - .replace(/([A-Z][^A-Z+])/g, " $1") - .replace(/([A-Z][^a-z+])/g, " $1") - .replace(/\s\s/g, '') - .trim(); + + var formattedString = ''; + var i = 0; + while (i <= unformattedString.length) { + var ch = unformattedString.charAt(i); + var nextChar = unformattedString.charAt(i + 1); + + if (ch == ch.toLowerCase() && nextChar == nextChar.toUpperCase()) { + formattedString = formattedString.trim() + ch + ' '; + } else if (ch == ch.toUpperCase() && nextChar == nextChar.toLowerCase() && nextChar != nextChar.toUpperCase() && nextChar != '') { + formattedString = formattedString.trim() + ' ' + ch; + } else { + formattedString += ch; + } + i++; + } + + return formattedString.trim(); } function removeBeginningHash(hashedString) { diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js index e03d40259..2ba200bc5 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js @@ -2,8 +2,9 @@ equal(addSpacesToCamelCasedString("ThisIsATestString"), "This Is A Test String", "Happy path test"); equal(addSpacesToCamelCasedString("00ThisIsATestString"), "00 This Is A Test String", "String prefaced by numbers"); equal(addSpacesToCamelCasedString("ThisIsATestString."), "This Is A Test String.", "String ending with punctuation."); - equal(addSpacesToCamelCasedString("ThisIsATestStringABC"), "This Is A Test String ABC", "String with abbreviation at the end."); - equal(addSpacesToCamelCasedString("ABCThisIsATestString"), "ABC This Is A Test String", "String with abbreviation at the beginning."); + equal(addSpacesToCamelCasedString("ThisIsATestStringABC"), "This Is A Test String ABC", "String with abbreviation at the end"); + equal(addSpacesToCamelCasedString("ThisIsATestStringABC."), "This Is A Test String ABC.", "String with abbreviation and punctuation"); + equal(addSpacesToCamelCasedString("ABCThisIsATestString"), "ABC This Is A Test String", "String with abbreviation at the beginning"); }); test("Can pull off # from hashtag", function() {