X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fstring%2FString2.java;h=07e3fdb83ccc81d366ab0734121fe475c85adb22;hp=705df579627140832f6197eb198592215a44d65b;hb=b1ffc7025cc976821987469570f07a7298ea16c9;hpb=443c6a564efa9f5868fd81c0db23a480cbe3cab4 diff --git a/src/main/java/eu/svjatoslav/commons/string/String2.java b/src/main/java/eu/svjatoslav/commons/string/String2.java index 705df57..07e3fdb 100755 --- a/src/main/java/eu/svjatoslav/commons/string/String2.java +++ b/src/main/java/eu/svjatoslav/commons/string/String2.java @@ -1,16 +1,13 @@ /* - * Svjatoslav Commons - shared library of common functionality. - * Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. + * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - package eu.svjatoslav.commons.string; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class String2 { @@ -20,6 +17,18 @@ public class String2 { addSuffix(value); } + public String2() { + } + + public String2 repeat(int count){ + String value = toString(); + + for (int i = 1; i < count; i++) { + addSuffix(value); + } + return this; + } + public String2 addPrefix(final String prefix) { if (prefix == null) return this; @@ -50,6 +59,12 @@ public class String2 { return this; } + public String2 addSuffix(String s, int times) { + for (int i = 0; i < times; i++) addSuffix(s); + return this; + } + + /** * Cut given amount of characters from the left of the string. * @@ -152,4 +167,19 @@ public class String2 { public String toString() { return getSubString(0, chars.size()); } + + + public static String[] getGroups(String s, String regexp){ + Pattern pattern = Pattern.compile(regexp); + Matcher matcher = pattern.matcher(s); + + matcher.find(); + String[] result = new String[matcher.groupCount()]; + + for (int i = 0; i< result.length; i++){ + result[i] = matcher.group(i+1); + } + + return result; + } }