tbw777 opened a new pull request, #5311:
URL: https://github.com/apache/netbeans/pull/5311

   replace() method is more fast then replaceAll() for non regex cases
   
   Tests to proof correctly changes:
   `        {
               var testStr = "...|string ||. |||...||||";
   
               var str1 = testStr.replace("|", "");
               var str2 = testStr.replaceAll("|", "");
               test(str1, str2);
   
               // ...string . ...
               // ...|string ||. |||...||||
               // FALSE
           }
   
           {
               var testStr = "\\ABC \\\\ ASDF 4\\\\FDS \\ sdf \\ asdf \\\\\\";
   
               //equals
               var str1 = testStr.replace("\\", "/");
               var str2 = testStr.replaceAll("\\\\", "/");
               test(str1, str2);
   
               // /ABC // ASDF 4//FDS / sdf / asdf ///
               // /ABC // ASDF 4//FDS / sdf / asdf ///
               // true
           }
   
           {
               var testStr = "...\\string \\. \\...";
   
               var str1 = testStr.replace(".", "");
               var str2 = testStr.replaceAll("\\.", "");
               test(str1, str2);
   
               // \string \ \
               // \string \ \
               // true
           }
   
           {
               var testStr = ".{{..{string {\\} 1234{\\\\\\{}. 
\\{{{{...\\\\{...\\\\\\\\{{{";
   
               var str1 = testStr.replace("{", "'{'");
               var str2 = testStr.replaceAll("\\{", "'\\{'");
               test(str1, str2);
   
               // .'{''{'..'{'string '{'\} 1234'{'\\\'{'}. 
\'{''{''{''{'...\\'{'...\\\\'{''{''{'
               // .'{''{'..'{'string '{'\} 1234'{'\\\'{'}. 
\'{''{''{''{'...\\'{'...\\\\'{''{''{'
               // true
           }
   
           {
               var testStr = ".}}..}string }\\} 1234}\\\\\\}}. 
\\}}}}...\\\\}...\\\\\\\\}}}";
   
               var str1 = testStr.replace("}", "'}'");
               var str2 = testStr.replaceAll("\\}", "'\\}'");
               test(str1, str2);
   
               // .'}''}'..'}'string '}'\'}' 1234'}'\\\'}''}'. 
\'}''}''}''}'...\\'}'...\\\\'}''}''}'
               // .'}''}'..'}'string '}'\'}' 1234'}'\\\'}''}'. 
\'}''}''}''}'...\\'}'...\\\\'}''}''}'
               // true
           }
   
           {
               var testStr = ".}}..'{'st'}'\\} 1234}\\\\\\}}. \\}}'{'st}} 
{'st'}'...''{'st'}'\\\\}...\\\\\\\\}''{'st'}''}}";
   
               var str1 = testStr.replace("'{'" + "st" + "'}'","{" + "st" + 
"}");
               var str2 = testStr.replaceAll("'\\{'" + "st" + "'\\}'", "\\{" + 
"st" + "\\}");
               test(str1, str2);
   
               // .}}..{st}\} 1234}\\\}}. \}}'{'st}} 
{'st'}'...'{st}\\}...\\\\}'{st}'}}
               // .}}..{st}\} 1234}\\\}}. \}}'{'st}} 
{'st'}'...'{st}\\}...\\\\}'{st}'}}
               // true
           }
   
           {
               var testStr = "abc\nabcd\n\nabcd123\n\n\n";
   
               var str1 = testStr.replace("\n", "<br>");
               var str2 = testStr.replaceAll("\\n", "<br>");
               test(str1, str2);
   
               // abc<br>abcd<br><br>abcd123<br><br><br>
               // abc<br>abcd<br><br>abcd123<br><br><br>
               // true
           }
   
           {
               var testStr = "\\\\ \\ \\\\\\ \\\\1 \\2 \\\\\\3 \\\\d \\d 
\\\\\\d \\\\\\ddd";
   
               var str1 = testStr.replace("\\d", ":");
               var str2 = testStr.replaceAll("\\\\d", ":");
               test(str1, str2);
   
               // \\ \ \\\ \\1 \2 \\\3 \: : \\: \\:dd
               // \\ \ \\\ \\1 \2 \\\3 \: : \\: \\:dd
               // true
           }
   
           {
               var testStr = "\\\\ \\ \\\\\\ \\\\1 \\2 \\\\\\3 \\\\n \\n 
\\\\\\n \\\\\\n \n\n \\\\ n\n";
   
               var str1 = testStr.replace("\\n", " ");
               var str2 = testStr.replaceAll("\\\\n", " ");
               test(str1, str2);
   
               // \\ \ \\\ \\1 \2 \\\3 \    \\  \\
               //
               //  \\ n
               //
               // \\ \ \\\ \\1 \2 \\\3 \    \\  \\
               //
               //  \\ n
               //
               // true
           }
   
   
           {
               var testStr = "\\\\ \\ \\\\\\ \\\\1 \\2 \\\\\\3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace("\\\\", "\\");
               var str2 = testStr.replaceAll("\\\\\\\\", "\\\\");
               test(str1, str2);
   
               // \ \ \\ \1 \2 \\3 \ \ \\ \\ \ \ n\
               // \ \ \\ \1 \2 \\3 \ \ \\ \\ \ \ n\
               // true
           }
   
           //
   
           {
               var testStr = "\\\\ \\ \\\\\\ \\\\1 \\2 \\\\\\3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace("\\", "/");
               var str2 = testStr.replaceAll("\\\\", "/");
               test(str1, str2);
   
               // // / /// //1 /2 ///3 // / /// /// / // n/
               // // / /// //1 /2 ///3 // / /// /// / // n/
               // true
           }
   
           {
               var testStr = "\\\\ \\ \\   \\ \\\\1 \\2 \\    3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace(" ", "%20");
               var str2 = testStr.replaceAll(" ", "%20");
               test(str1, str2);
   
               // 
\\%20\%20\%20%20%20\%20\\1%20\2%20\%20%20%20%203%20\\%20\%20\\\%20\\\%20\%20\\%20n\
               // 
\\%20\%20\%20%20%20\%20\\1%20\2%20\%20%20%20%203%20\\%20\%20\\\%20\\\%20\%20\\%20n\
               // true
           }
   
           {
               var testStr = "\\\\ \\ \\   \\ \\\\1 \\2 \\    3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace(" ", "");
               var str2 = testStr.replaceAll(" +", "");
               test(str1, str2);
   
               // \\\\\\\1\2\3\\\\\\\\\\\\n\
               // \\\\\\\1\2\3\\\\\\\\\\\\n\
               // true
           }
   
           {
               var testStr = 
"\\\\*\\*\\***\\*\\\\1*\\2*\\****3*\\\\*\\*\\\\\\*\\\\\\*\\*\\\\*n\\";
   
               var str1 = testStr.replace("**", "(.+/)?");
               var str2 = testStr.replaceAll("\\*\\*", "(.+/)?");
               test(str1, str2);
   
               // \\*\*\(.+/)?*\*\\1*\2*\(.+/)?(.+/)?3*\\*\*\\\*\\\*\*\\*n\
               // \\*\*\(.+/)?*\*\\1*\2*\(.+/)?(.+/)?3*\\*\*\\\*\\\*\*\\*n\
               // true
           }
   
           {
               var testStr = 
"\\\\*\\*\\***\\*\\\\1*\\2*\\****3*\\\\*\\*\\\\\\*\\\\\\*\\*\\\\*n\\";
   
               var str1 = testStr.replace("*", "(.+/)?");
               var str2 = testStr.replaceAll("\\*", "(.+/)?");
               test(str1, str2);
   
               // 
\\(.+/)?\(.+/)?\(.+/)?(.+/)?(.+/)?\(.+/)?\\1(.+/)?\2(.+/)?\(.+/)?(.+/)?(.+/)?(.+/)?3(.+/)?\\(.+/)?\(.+/)?\\\(.+/)?\\\(.+/)?\(.+/)?\\(.+/)?n\
               // 
\\(.+/)?\(.+/)?\(.+/)?(.+/)?(.+/)?\(.+/)?\\1(.+/)?\2(.+/)?\(.+/)?(.+/)?(.+/)?(.+/)?3(.+/)?\\(.+/)?\(.+/)?\\\(.+/)?\\\(.+/)?\(.+/)?\\(.+/)?n\
               // true
           }
   
           {
               var testStr = "\\\\ \\ \\   \\ \\\\1 \\2 \\    3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace("  ", " ");
               var str2 = testStr.replaceAll(" +", " ");
               test(str1, str2);
   
               // \\ \ \  \ \\1 \2 \  3 \\ \ \\\ \\\ \ \\ n\
               // \\ \ \ \ \\1 \2 \ 3 \\ \ \\\ \\\ \ \\ n\
               // FALSE
           }
   
   
           {
               var testStr = "\\\\ \\ \\   \\ \\\\1 \\2 \\    3 \\\\ \\ \\\\\\ 
\\\\\\ \\ \\\\ n\\";
   
               var str1 = testStr.replace(" ", " ");
               var str2 = testStr.replaceAll(" ", " ");
               test(str1, str2);
   
               // \\ \ \   \ \\1 \2 \    3 \\ \ \\\ \\\ \ \\ n\
               // \\ \ \   \ \\1 \2 \    3 \\ \ \\\ \\\ \ \\ n\
               // true
           }
   
           {
               var testStr = " / / / /  / /  / /    / /  / / / /1  / /2  / /    
3  / / / /  / /  / / / / / /  / / / / / /  / /  / / / / n / /";
   
               var str1 = testStr.replace(".", "\\*");
               var str2 = testStr.replaceAll(".", "\\*");
               test(str1, str2);
   
               //  / / / /  / /  / /    / /  / / / /1  / /2  / /    3  / / / /  
/ /  / / / / / /  / / / / / /  / /  / / / / n / /
               // 
***************************************************************************************************************
               // FALSE
           }
   
           {
               var testStr = 
"#/#/#/#/##/#/##/#/####/#/##/#/#/#/1##/#/2##/#/####3##/#/#/#/##/#/##/#/#/#/#/#/##/#/#/#/#/#/##/#/##/#/#/#/#n#/#/";
   
               var str1 = testStr.replace("#", "\"");
               var str2 = testStr.replaceAll("#", "\"");
               test(str1, str2);
   
               // 
"/"/"/"/""/"/""/"/""""/"/""/"/"/"/1""/"/2""/"/""""3""/"/"/"/""/"/""/"/"/"/"/"/""/"/"/"/"/"/""/"/""/"/"/"/"n"/"/
               // 
"/"/"/"/""/"/""/"/""""/"/""/"/"/"/1""/"/2""/"/""""3""/"/"/"/""/"/""/"/"/"/"/"/""/"/"/"/"/"/""/"/""/"/"/"/"n"/"/
               // true
           }
   
   
           {
               var testStr = 
",/,/,/,/,,/,/,,/,/,,,,/,/,,/,/,/,/1,,/,/2,,/,/,,,,3,,/,/,/,/,,/,/,,/,/,/,/,/,/,,/,/,/,/,/,/,,/,/,,/,/,/,/,n,/,/";
   
               var str1 = testStr.replace(",", "1");
               var str2 = testStr.replaceAll(",", "1");
               test(str1, str2);
   
               // 
1/1/1/1/11/1/11/1/1111/1/11/1/1/1/111/1/211/1/1111311/1/1/1/11/1/11/1/1/1/1/1/11/1/1/1/1/1/11/1/11/1/1/1/1n1/1/
               // 
1/1/1/1/11/1/11/1/1111/1/11/1/1/1/111/1/211/1/1111311/1/1/1/11/1/11/1/1/1/1/1/11/1/1/1/1/1/11/1/11/1/1/1/1n1/1/
               // true
           }
   
           {
               var testStr = 
"-/-/-/-/--/-/--/-/----/-/--/-/-/-/1--/-/2--/-/----3--/-/-/-/--/-/--/-/-/-/-/-/--/-/-/-/-/-/--/-/--/-/-/-/-n-/-/";
   
               var str1 = testStr.replace("-", "1");
               var str2 = testStr.replaceAll("-", "1");
               test(str1, str2);
   
               // 
1/1/1/1/11/1/11/1/1111/1/11/1/1/1/111/1/211/1/1111311/1/1/1/11/1/11/1/1/1/1/1/11/1/1/1/1/1/11/1/11/1/1/1/1n1/1/
               // 
1/1/1/1/11/1/11/1/1111/1/11/1/1/1/111/1/211/1/1111311/1/1/1/11/1/11/1/1/1/1/1/11/1/1/1/1/1/11/1/11/1/1/1/1n1/1/
               // true
           }`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to