diff --git a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js index 8a641be6e..da4267467 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/js/stringFormatting.js @@ -2,12 +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])/g, " $1").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 9f122e406..2ba200bc5 100644 --- a/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js +++ b/src/Pickles/Pickles.BaseDhtmlFiles/tests/tests.js @@ -1,7 +1,10 @@ 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 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() {