Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Automated rollback of commit 9bd3a15.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 413057968
Change-Id: Ibf9f714e367c8cd990d25d58f3ca15d903f790d2
  • Loading branch information
Closure Team authored and copybara-github committed Nov 30, 2021
1 parent 9bd3a15 commit 934a018
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions closure/goog/string/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,27 @@ goog.string.makeSafe = function(obj) {
return obj == null ? '' : String(obj);
};


/**
* Concatenates string expressions. This is useful
* since some browsers are very inefficient when it comes to using plus to
* concat strings. Be careful when using null and undefined here since
* these will not be included in the result. If you need to represent these
* be sure to cast the argument to a String first.
* For example:
* <pre>buildString('a', 'b', 'c', 'd') -> 'abcd'
* buildString(null, undefined) -> ''
* </pre>
* @param {...*} var_args A list of strings to concatenate. If not a string,
* it will be casted to one.
* @return {string} The concatenation of `var_args`.
*/
goog.string.buildString = function(var_args) {
'use strict';
return Array.prototype.join.call(arguments, '');
};


/**
* Returns a string with at least 64-bits of randomness.
*
Expand Down
12 changes: 12 additions & 0 deletions closure/goog/string/string_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,18 @@ testSuite({
assertEquals('foofoofoofoofoofoo', googString.repeat('foo', 6));
},

testBuildString() {
assertEquals('', googString.buildString());
assertEquals('a', googString.buildString('a'));
assertEquals('ab', googString.buildString('ab'));
assertEquals('ab', googString.buildString('a', 'b'));
assertEquals('abcd', googString.buildString('a', 'b', 'c', 'd'));
assertEquals('0', googString.buildString(0));
assertEquals('0123', googString.buildString(0, 1, 2, 3));
assertEquals('ab01', googString.buildString('a', 'b', 0, 1));
assertEquals('', googString.buildString(null, undefined));
},

testCompareVersions() {
const f = googString.compareVersions;
assertTrue('numeric equality broken', f(1, 1) == 0);
Expand Down

0 comments on commit 934a018

Please sign in to comment.