aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2014-06-11 23:52:18 +0200
committerrsudev <rasch@munin-soft.de>2014-06-12 00:15:20 +0200
commitf04d04a2b2438416335e6a5b03a21568912fa15f (patch)
tree975afd91c3d1ea0ee07f7cd7b3ff5ee3478cc697 /main/src/cgeo/geocaching/utils
parent24e030f2e68796d0d37f2762d70181b2fb12b862 (diff)
downloadcgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.zip
cgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.tar.gz
cgeo-f04d04a2b2438416335e6a5b03a21568912fa15f.tar.bz2
Implements #3894, Only show Changelog on startup if hash code changed
- switched from version checking to checksum checking
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
-rw-r--r--main/src/cgeo/geocaching/utils/TextUtils.java20
1 files changed, 17 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/utils/TextUtils.java b/main/src/cgeo/geocaching/utils/TextUtils.java
index ef09f32..77aa167 100644
--- a/main/src/cgeo/geocaching/utils/TextUtils.java
+++ b/main/src/cgeo/geocaching/utils/TextUtils.java
@@ -4,11 +4,13 @@
package cgeo.geocaching.utils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
import org.eclipse.jdt.annotation.Nullable;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.zip.CRC32;
/**
* Misc. utils. All methods don't use Android specific stuff to use these methods in plain JUnit tests.
@@ -52,7 +54,7 @@ public final class TextUtils {
result = matcher.group(group);
}
if (null != result) {
- Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(result);
+ final Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(result);
result = remover.replaceAll(" ");
return trim ? new String(result).trim() : new String(result);
@@ -134,7 +136,7 @@ public final class TextUtils {
data.getChars(0, length, chars, 0);
int resultSize = 0;
boolean lastWasWhitespace = true;
- for (char c : chars) {
+ for (final char c : chars) {
if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
if (!lastWasWhitespace) {
chars[resultSize++] = ' ';
@@ -167,8 +169,20 @@ public final class TextUtils {
* @return
*/
public static String removeControlCharacters(final String input) {
- Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(input);
+ final Matcher remover = PATTERN_REMOVE_NONPRINTABLE.matcher(input);
return remover.replaceAll(" ").trim();
}
+ /**
+ * Calculate a simple checksum for change-checking (not usable for security/cryptography!)
+ *
+ * @param input
+ * String to check
+ * @return resulting checksum
+ */
+ public static long checksum(final String input) {
+ final CRC32 checksum = new CRC32();
+ checksum.update(input.getBytes());
+ return checksum.getValue();
+ }
}