define UTF-8 as source code encoding
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / string / CuttableString.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.commons.string;
11
12 public class CuttableString {
13
14         private String value;
15
16         public CuttableString(final String value) {
17                 this.value = value;
18         }
19
20         /**
21          * Cut given amount of characters from the left of the string. Return cutted
22          * part.
23          */
24         public String cutLeft(final int cutAmount) {
25
26                 int actualCutAmount = cutAmount;
27
28                 if (actualCutAmount > value.length())
29                         actualCutAmount = value.length();
30
31                 final String result = value.substring(0, actualCutAmount);
32
33                 value = value.substring(actualCutAmount);
34
35                 return result;
36         }
37
38         public int getLength() {
39                 return value.length();
40         };
41
42         public String getValue() {
43                 return value;
44         }
45
46         public boolean isEmpty() {
47                 return value.length() == 0;
48         }
49 }