StringUtil.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. package org.zhongzheng.common.utils;
  2. //
  3. // Source code recreated from a .class file by IntelliJ IDEA
  4. // (powered by FernFlower decompiler)
  5. //
  6. import java.io.StringReader;
  7. import java.io.StringWriter;
  8. import java.text.MessageFormat;
  9. import java.util.ArrayList;
  10. import java.util.Collection;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.UUID;
  15. import java.util.concurrent.ThreadLocalRandom;
  16. import java.util.stream.Stream;
  17. import org.springframework.util.ObjectUtils;
  18. import org.zhongzheng.common.utils.StrFormatter;
  19. import org.xupeng.common.utils.StrSpliter;
  20. import org.springframework.lang.Nullable;
  21. import org.springframework.util.Assert;
  22. import org.springframework.util.StringUtils;
  23. import org.springframework.web.util.HtmlUtils;
  24. public class StringUtil extends StringUtils {
  25. public static final int INDEX_NOT_FOUND = -1;
  26. private static final String S_INT = "0123456789";
  27. private static final String S_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  28. private static final String S_ALL = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  29. public StringUtil() {
  30. }
  31. public static boolean isBlank(final CharSequence cs) {
  32. return !hasText(cs);
  33. }
  34. public static boolean isNotBlank(final CharSequence cs) {
  35. return hasText(cs);
  36. }
  37. public static boolean isAnyBlank(final CharSequence... css) {
  38. return ObjectUtils.isEmpty(css) ? true : Stream.of(css).anyMatch(StringUtil::isBlank);
  39. }
  40. public static boolean isNoneBlank(final CharSequence... css) {
  41. return ObjectUtils.isEmpty(css) ? false : Stream.of(css).allMatch(StringUtil::isNotBlank);
  42. }
  43. public static boolean isNumeric(final CharSequence cs) {
  44. if (isBlank(cs)) {
  45. return false;
  46. } else {
  47. int i = cs.length();
  48. char chr;
  49. do {
  50. --i;
  51. if (i < 0) {
  52. return true;
  53. }
  54. chr = cs.charAt(i);
  55. } while(chr >= '0' && chr <= '9');
  56. return false;
  57. }
  58. }
  59. public static String join(Collection<?> coll) {
  60. return collectionToCommaDelimitedString(coll);
  61. }
  62. public static String join(Collection<?> coll, String delim) {
  63. return collectionToDelimitedString(coll, delim);
  64. }
  65. public static String join(Object[] arr) {
  66. return arrayToCommaDelimitedString(arr);
  67. }
  68. public static String join(Object[] arr, String delim) {
  69. return arrayToDelimitedString(arr, delim);
  70. }
  71. public static String randomUUID() {
  72. ThreadLocalRandom random = ThreadLocalRandom.current();
  73. return (new UUID(random.nextLong(), random.nextLong())).toString().replace("-", "");
  74. }
  75. public static String escapeHtml(String html) {
  76. return isBlank(html) ? "" : HtmlUtils.htmlEscape(html);
  77. }
  78. public static String cleanChars(String txt) {
  79. return txt.replaceAll("[  `·•�\u0001\\f\\t\\v\\s]", "");
  80. }
  81. public static String random(int count) {
  82. return random(count, RandomType.ALL);
  83. }
  84. public static String random(int count, RandomType randomType) {
  85. if (count == 0) {
  86. return "";
  87. } else {
  88. Assert.isTrue(count > 0, "Requested random string length " + count + " is less than 0.");
  89. ThreadLocalRandom random = ThreadLocalRandom.current();
  90. char[] buffer = new char[count];
  91. for(int i = 0; i < count; ++i) {
  92. if (RandomType.INT == randomType) {
  93. buffer[i] = "0123456789".charAt(random.nextInt("0123456789".length()));
  94. } else if (RandomType.STRING == randomType) {
  95. buffer[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(random.nextInt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".length()));
  96. } else {
  97. buffer[i] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(random.nextInt("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".length()));
  98. }
  99. }
  100. return new String(buffer);
  101. }
  102. }
  103. public static String format(CharSequence template, Object... params) {
  104. if (null == template) {
  105. return null;
  106. } else {
  107. return !Func.isEmpty(params) && !isBlank(template) ? StrFormatter.format(template.toString(), params) : template.toString();
  108. }
  109. }
  110. public static String indexedFormat(CharSequence pattern, Object... arguments) {
  111. return MessageFormat.format(pattern.toString(), arguments);
  112. }
  113. public static String format(CharSequence template, Map<?, ?> map) {
  114. if (null == template) {
  115. return null;
  116. } else if (null != map && !map.isEmpty()) {
  117. String template2 = template.toString();
  118. Map.Entry entry;
  119. for(Iterator var3 = map.entrySet().iterator(); var3.hasNext(); template2 = template2.replace("{" + entry.getKey() + "}", Func.toStr(entry.getValue()))) {
  120. entry = (Map.Entry)var3.next();
  121. }
  122. return template2;
  123. } else {
  124. return template.toString();
  125. }
  126. }
  127. @Nullable
  128. public static String cleanIdentifier(@Nullable String param) {
  129. if (param == null) {
  130. return null;
  131. } else {
  132. StringBuilder paramBuilder = new StringBuilder();
  133. for(int i = 0; i < param.length(); ++i) {
  134. char c = param.charAt(i);
  135. if (Character.isJavaIdentifierPart(c)) {
  136. paramBuilder.append(c);
  137. }
  138. }
  139. return paramBuilder.toString();
  140. }
  141. }
  142. public static List<String> split(CharSequence str, char separator, int limit) {
  143. return split(str, separator, limit, false, false);
  144. }
  145. public static List<String> splitTrim(CharSequence str, char separator) {
  146. return splitTrim(str, separator, -1);
  147. }
  148. public static List<String> splitTrim(CharSequence str, CharSequence separator) {
  149. return splitTrim(str, separator, -1);
  150. }
  151. public static List<String> splitTrim(CharSequence str, char separator, int limit) {
  152. return split(str, separator, limit, true, true);
  153. }
  154. public static List<String> splitTrim(CharSequence str, CharSequence separator, int limit) {
  155. return split(str, separator, limit, true, true);
  156. }
  157. public static List<String> split(CharSequence str, char separator, boolean isTrim, boolean ignoreEmpty) {
  158. return split(str, separator, 0, isTrim, ignoreEmpty);
  159. }
  160. public static List<String> split(CharSequence str, char separator, int limit, boolean isTrim, boolean ignoreEmpty) {
  161. return (List)(null == str ? new ArrayList(0) : StrSpliter.split(str.toString(), separator, limit, isTrim, ignoreEmpty));
  162. }
  163. public static List<String> split(CharSequence str, CharSequence separator, int limit, boolean isTrim, boolean ignoreEmpty) {
  164. if (null == str) {
  165. return new ArrayList(0);
  166. } else {
  167. String separatorStr = null == separator ? null : separator.toString();
  168. return StrSpliter.split(str.toString(), separatorStr, limit, isTrim, ignoreEmpty);
  169. }
  170. }
  171. public static String[] split(CharSequence str, CharSequence separator) {
  172. if (str == null) {
  173. return new String[0];
  174. } else {
  175. String separatorStr = null == separator ? null : separator.toString();
  176. return StrSpliter.splitToArray(str.toString(), separatorStr, 0, false, false);
  177. }
  178. }
  179. public static String[] split(CharSequence str, int len) {
  180. return null == str ? new String[0] : StrSpliter.splitByLength(str.toString(), len);
  181. }
  182. public static boolean contains(CharSequence str, char searchChar) {
  183. return indexOf(str, searchChar) > -1;
  184. }
  185. public static boolean containsAny(CharSequence str, CharSequence... testStrs) {
  186. return null != getContainsStr(str, testStrs);
  187. }
  188. public static String getContainsStr(CharSequence str, CharSequence... testStrs) {
  189. if (!isEmpty(str) && !Func.isEmpty(testStrs)) {
  190. CharSequence[] var2 = testStrs;
  191. int var3 = testStrs.length;
  192. for(int var4 = 0; var4 < var3; ++var4) {
  193. CharSequence checkStr = var2[var4];
  194. if (str.toString().contains(checkStr)) {
  195. return checkStr.toString();
  196. }
  197. }
  198. return null;
  199. } else {
  200. return null;
  201. }
  202. }
  203. public static boolean containsIgnoreCase(CharSequence str, CharSequence testStr) {
  204. if (null == str) {
  205. return null == testStr;
  206. } else {
  207. return str.toString().toLowerCase().contains(testStr.toString().toLowerCase());
  208. }
  209. }
  210. public static boolean containsAnyIgnoreCase(CharSequence str, CharSequence... testStrs) {
  211. return null != getContainsStrIgnoreCase(str, testStrs);
  212. }
  213. public static String getContainsStrIgnoreCase(CharSequence str, CharSequence... testStrs) {
  214. if (!isEmpty(str) && !Func.isEmpty(testStrs)) {
  215. CharSequence[] var2 = testStrs;
  216. int var3 = testStrs.length;
  217. for(int var4 = 0; var4 < var3; ++var4) {
  218. CharSequence testStr = var2[var4];
  219. if (containsIgnoreCase(str, testStr)) {
  220. return testStr.toString();
  221. }
  222. }
  223. return null;
  224. } else {
  225. return null;
  226. }
  227. }
  228. public static String sub(CharSequence str, int fromIndex, int toIndex) {
  229. if (isEmpty(str)) {
  230. return "";
  231. } else {
  232. int len = str.length();
  233. if (fromIndex < 0) {
  234. fromIndex += len;
  235. if (fromIndex < 0) {
  236. fromIndex = 0;
  237. }
  238. } else if (fromIndex > len) {
  239. fromIndex = len;
  240. }
  241. if (toIndex < 0) {
  242. toIndex += len;
  243. if (toIndex < 0) {
  244. toIndex = len;
  245. }
  246. } else if (toIndex > len) {
  247. toIndex = len;
  248. }
  249. if (toIndex < fromIndex) {
  250. int tmp = fromIndex;
  251. fromIndex = toIndex;
  252. toIndex = tmp;
  253. }
  254. return fromIndex == toIndex ? "" : str.toString().substring(fromIndex, toIndex);
  255. }
  256. }
  257. public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator) {
  258. if (!isEmpty(string) && separator != null) {
  259. String str = string.toString();
  260. String sep = separator.toString();
  261. if (sep.isEmpty()) {
  262. return "";
  263. } else {
  264. int pos = isLastSeparator ? str.lastIndexOf(sep) : str.indexOf(sep);
  265. return pos == -1 ? str : str.substring(0, pos);
  266. }
  267. } else {
  268. return null == string ? null : string.toString();
  269. }
  270. }
  271. public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator) {
  272. if (isEmpty(string)) {
  273. return null == string ? null : string.toString();
  274. } else if (separator == null) {
  275. return "";
  276. } else {
  277. String str = string.toString();
  278. String sep = separator.toString();
  279. int pos = isLastSeparator ? str.lastIndexOf(sep) : str.indexOf(sep);
  280. return pos == -1 ? "" : str.substring(pos + separator.length());
  281. }
  282. }
  283. public static String subBetween(CharSequence str, CharSequence before, CharSequence after) {
  284. if (str != null && before != null && after != null) {
  285. String str2 = str.toString();
  286. String before2 = before.toString();
  287. String after2 = after.toString();
  288. int start = str2.indexOf(before2);
  289. if (start != -1) {
  290. int end = str2.indexOf(after2, start + before2.length());
  291. if (end != -1) {
  292. return str2.substring(start + before2.length(), end);
  293. }
  294. }
  295. return null;
  296. } else {
  297. return null;
  298. }
  299. }
  300. public static String subBetween(CharSequence str, CharSequence beforeAndAfter) {
  301. return subBetween(str, beforeAndAfter, beforeAndAfter);
  302. }
  303. public static String removePrefix(CharSequence str, CharSequence prefix) {
  304. if (!isEmpty(str) && !isEmpty(prefix)) {
  305. String str2 = str.toString();
  306. return str2.startsWith(prefix.toString()) ? subSuf(str2, prefix.length()) : str2;
  307. } else {
  308. return "";
  309. }
  310. }
  311. public static String removePrefixIgnoreCase(CharSequence str, CharSequence prefix) {
  312. if (!isEmpty(str) && !isEmpty(prefix)) {
  313. String str2 = str.toString();
  314. return str2.toLowerCase().startsWith(prefix.toString().toLowerCase()) ? subSuf(str2, prefix.length()) : str2;
  315. } else {
  316. return "";
  317. }
  318. }
  319. public static String removeSuffix(CharSequence str, CharSequence suffix) {
  320. if (!isEmpty(str) && !isEmpty(suffix)) {
  321. String str2 = str.toString();
  322. return str2.endsWith(suffix.toString()) ? subPre(str2, str2.length() - suffix.length()) : str2;
  323. } else {
  324. return "";
  325. }
  326. }
  327. public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix) {
  328. return lowerFirst(removeSuffix(str, suffix));
  329. }
  330. public static String removeSuffixIgnoreCase(CharSequence str, CharSequence suffix) {
  331. if (!isEmpty(str) && !isEmpty(suffix)) {
  332. String str2 = str.toString();
  333. return str2.toLowerCase().endsWith(suffix.toString().toLowerCase()) ? subPre(str2, str2.length() - suffix.length()) : str2;
  334. } else {
  335. return "";
  336. }
  337. }
  338. public static String lowerFirst(String str) {
  339. char firstChar = str.charAt(0);
  340. if (firstChar >= 'A' && firstChar <= 'Z') {
  341. char[] arr = str.toCharArray();
  342. arr[0] = (char)(arr[0] + 32);
  343. return new String(arr);
  344. } else {
  345. return str;
  346. }
  347. }
  348. public static String upperFirst(String str) {
  349. char firstChar = str.charAt(0);
  350. if (firstChar >= 'a' && firstChar <= 'z') {
  351. char[] arr = str.toCharArray();
  352. arr[0] = (char)(arr[0] - 32);
  353. return new String(arr);
  354. } else {
  355. return str;
  356. }
  357. }
  358. public static String subPre(CharSequence string, int toIndex) {
  359. return sub(string, 0, toIndex);
  360. }
  361. public static String subSuf(CharSequence string, int fromIndex) {
  362. return isEmpty(string) ? null : sub(string, fromIndex, string.length());
  363. }
  364. public static int indexOf(final CharSequence str, char searchChar) {
  365. return indexOf(str, searchChar, 0);
  366. }
  367. public static int indexOf(final CharSequence str, char searchChar, int start) {
  368. return str instanceof String ? ((String)str).indexOf(searchChar, start) : indexOf(str, searchChar, start, -1);
  369. }
  370. public static int indexOf(final CharSequence str, char searchChar, int start, int end) {
  371. int len = str.length();
  372. if (start < 0 || start > len) {
  373. start = 0;
  374. }
  375. if (end > len || end < 0) {
  376. end = len;
  377. }
  378. for(int i = start; i < end; ++i) {
  379. if (str.charAt(i) == searchChar) {
  380. return i;
  381. }
  382. }
  383. return -1;
  384. }
  385. public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) {
  386. return indexOfIgnoreCase(str, searchStr, 0);
  387. }
  388. public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr, int fromIndex) {
  389. return indexOf(str, searchStr, fromIndex, true);
  390. }
  391. public static int indexOf(final CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) {
  392. if (str != null && searchStr != null) {
  393. if (fromIndex < 0) {
  394. fromIndex = 0;
  395. }
  396. int endLimit = str.length() - searchStr.length() + 1;
  397. if (fromIndex > endLimit) {
  398. return -1;
  399. } else if (searchStr.length() == 0) {
  400. return fromIndex;
  401. } else if (!ignoreCase) {
  402. return str.toString().indexOf(searchStr.toString(), fromIndex);
  403. } else {
  404. for(int i = fromIndex; i < endLimit; ++i) {
  405. if (isSubEquals(str, i, searchStr, 0, searchStr.length(), true)) {
  406. return i;
  407. }
  408. }
  409. return -1;
  410. }
  411. } else {
  412. return -1;
  413. }
  414. }
  415. public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) {
  416. return lastIndexOfIgnoreCase(str, searchStr, str.length());
  417. }
  418. public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr, int fromIndex) {
  419. return lastIndexOf(str, searchStr, fromIndex, true);
  420. }
  421. public static int lastIndexOf(final CharSequence str, final CharSequence searchStr, int fromIndex, boolean ignoreCase) {
  422. if (str != null && searchStr != null) {
  423. if (fromIndex < 0) {
  424. fromIndex = 0;
  425. }
  426. fromIndex = Math.min(fromIndex, str.length());
  427. if (searchStr.length() == 0) {
  428. return fromIndex;
  429. } else if (!ignoreCase) {
  430. return str.toString().lastIndexOf(searchStr.toString(), fromIndex);
  431. } else {
  432. for(int i = fromIndex; i > 0; --i) {
  433. if (isSubEquals(str, i, searchStr, 0, searchStr.length(), true)) {
  434. return i;
  435. }
  436. }
  437. return -1;
  438. }
  439. } else {
  440. return -1;
  441. }
  442. }
  443. public static int ordinalIndexOf(String str, String searchStr, int ordinal) {
  444. if (str != null && searchStr != null && ordinal > 0) {
  445. if (searchStr.length() == 0) {
  446. return 0;
  447. } else {
  448. int found = 0;
  449. int index = -1;
  450. do {
  451. index = str.indexOf(searchStr, index + 1);
  452. if (index < 0) {
  453. return index;
  454. }
  455. ++found;
  456. } while(found < ordinal);
  457. return index;
  458. }
  459. } else {
  460. return -1;
  461. }
  462. }
  463. public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase) {
  464. return null != str1 && null != str2 ? str1.toString().regionMatches(ignoreCase, start1, str2.toString(), start2, length) : false;
  465. }
  466. public static boolean equals(CharSequence str1, CharSequence str2) {
  467. return equals(str1, str2, false);
  468. }
  469. public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {
  470. return equals(str1, str2, true);
  471. }
  472. public static boolean equals(CharSequence str1, CharSequence str2, boolean ignoreCase) {
  473. if (null == str1) {
  474. return str2 == null;
  475. } else if (null == str2) {
  476. return false;
  477. } else {
  478. return ignoreCase ? str1.toString().equalsIgnoreCase(str2.toString()) : str1.equals(str2);
  479. }
  480. }
  481. public static StringBuilder builder() {
  482. return new StringBuilder();
  483. }
  484. public static StringBuilder builder(int capacity) {
  485. return new StringBuilder(capacity);
  486. }
  487. public static StringBuilder builder(CharSequence... strs) {
  488. StringBuilder sb = new StringBuilder();
  489. CharSequence[] var2 = strs;
  490. int var3 = strs.length;
  491. for(int var4 = 0; var4 < var3; ++var4) {
  492. CharSequence str = var2[var4];
  493. sb.append(str);
  494. }
  495. return sb;
  496. }
  497. public static StringBuilder appendBuilder(StringBuilder sb, CharSequence... strs) {
  498. CharSequence[] var2 = strs;
  499. int var3 = strs.length;
  500. for(int var4 = 0; var4 < var3; ++var4) {
  501. CharSequence str = var2[var4];
  502. sb.append(str);
  503. }
  504. return sb;
  505. }
  506. public static StringReader getReader(CharSequence str) {
  507. return null == str ? null : new StringReader(str.toString());
  508. }
  509. public static StringWriter getWriter() {
  510. return new StringWriter();
  511. }
  512. public static int count(CharSequence content, CharSequence strForSearch) {
  513. if (!Func.hasEmpty(new Object[]{content, strForSearch}) && strForSearch.length() <= content.length()) {
  514. int count = 0;
  515. int idx = 0;
  516. String content2 = content.toString();
  517. for(String strForSearch2 = strForSearch.toString(); (idx = content2.indexOf(strForSearch2, idx)) > -1; idx += strForSearch.length()) {
  518. ++count;
  519. }
  520. return count;
  521. } else {
  522. return 0;
  523. }
  524. }
  525. public static int count(CharSequence content, char charForSearch) {
  526. int count = 0;
  527. if (isEmpty(content)) {
  528. return 0;
  529. } else {
  530. int contentLength = content.length();
  531. for(int i = 0; i < contentLength; ++i) {
  532. if (charForSearch == content.charAt(i)) {
  533. ++count;
  534. }
  535. }
  536. return count;
  537. }
  538. }
  539. public static String underlineToHump(String para) {
  540. StringBuilder result = new StringBuilder();
  541. String[] a = para.split("_");
  542. String[] var3 = a;
  543. int var4 = a.length;
  544. for(int var5 = 0; var5 < var4; ++var5) {
  545. String s = var3[var5];
  546. if (result.length() == 0) {
  547. result.append(s.toLowerCase());
  548. } else {
  549. result.append(s.substring(0, 1).toUpperCase());
  550. result.append(s.substring(1).toLowerCase());
  551. }
  552. }
  553. return result.toString();
  554. }
  555. public static String humpToUnderline(String para) {
  556. para = lowerFirst(para);
  557. StringBuilder sb = new StringBuilder(para);
  558. int temp = 0;
  559. for(int i = 0; i < para.length(); ++i) {
  560. if (Character.isUpperCase(para.charAt(i))) {
  561. sb.insert(i + temp, "_");
  562. ++temp;
  563. }
  564. }
  565. return sb.toString().toLowerCase();
  566. }
  567. public static String lineToHump(String para) {
  568. StringBuilder result = new StringBuilder();
  569. String[] a = para.split("-");
  570. String[] var3 = a;
  571. int var4 = a.length;
  572. for(int var5 = 0; var5 < var4; ++var5) {
  573. String s = var3[var5];
  574. if (result.length() == 0) {
  575. result.append(s.toLowerCase());
  576. } else {
  577. result.append(s.substring(0, 1).toUpperCase());
  578. result.append(s.substring(1).toLowerCase());
  579. }
  580. }
  581. return result.toString();
  582. }
  583. public static String humpToLine(String para) {
  584. para = lowerFirst(para);
  585. StringBuilder sb = new StringBuilder(para);
  586. int temp = 0;
  587. for(int i = 0; i < para.length(); ++i) {
  588. if (Character.isUpperCase(para.charAt(i))) {
  589. sb.insert(i + temp, "-");
  590. ++temp;
  591. }
  592. }
  593. return sb.toString().toLowerCase();
  594. }
  595. public static String firstCharToLower(String str) {
  596. char firstChar = str.charAt(0);
  597. if (firstChar >= 'A' && firstChar <= 'Z') {
  598. char[] arr = str.toCharArray();
  599. arr[0] = (char)(arr[0] + 32);
  600. return new String(arr);
  601. } else {
  602. return str;
  603. }
  604. }
  605. public static String firstCharToUpper(String str) {
  606. char firstChar = str.charAt(0);
  607. if (firstChar >= 'a' && firstChar <= 'z') {
  608. char[] arr = str.toCharArray();
  609. arr[0] = (char)(arr[0] - 32);
  610. return new String(arr);
  611. } else {
  612. return str;
  613. }
  614. }
  615. }