MCPcopy Create free account
hub / github.com/Berkeley-CS61B/skeleton-sp23 / nextString

Method nextString

lab07/tests/StringUtils.java:41–49  ·  view source on GitHub ↗

Returns the string that comes right after S in alphabetical order. For example, if s is 'potato', this method will return 'potatp'. If the last character is a z, then we add to the next position, and so on.

(String s)

Source from the content-addressed store, hash-verified

39 * on.
40 */
41 public static String nextString(String s) {
42 /* Handle all zs as a special case to keep helper method simple. */
43 if (isAllzs(s)) {
44 return allAs(s.length() + 1);
45 }
46 char[] charVersion = s.toCharArray();
47 incrementCharArray(charVersion, charVersion.length - 1);
48 return new String(charVersion);
49 }
50
51 /** Helper function for nextString. Increments the Pth position of X
52 * by one, wrapping around to 'a' if p == 'z'. If wraparound occurs,

Callers 1

insertInOrderMethod · 0.95

Calls 3

isAllzsMethod · 0.95
allAsMethod · 0.95
incrementCharArrayMethod · 0.95

Tested by

no test coverage detected