| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package io.v.syncbase.v23.services.syncbase.util; |
| |
| import java.io.UnsupportedEncodingException; |
| |
| /** |
| * Various syncbase utility methods. |
| */ |
| public class Util { |
| /** |
| * Returns the start of the row range for the given prefix. |
| */ |
| public static String prefixRangeStart(String prefix) { |
| return prefix; |
| } |
| |
| /** |
| * Returns the limit of the row range for the given prefix. |
| */ |
| public static String prefixRangeLimit(String prefix) { |
| // We convert a string to a byte[] array, which can be thought of as a base-256 |
| // number. The code below effectively adds 1 to this number, then chops off any |
| // trailing 0x00 bytes. If the input string consists entirely of 0xFF, an empty string |
| // will be returned. |
| try { |
| byte[] bytes = prefix.getBytes("ISO8859-1"); |
| int last = bytes.length - 1; |
| for (; last >= 0 && bytes[last] == (byte) 0xFF; --last); |
| if (last < 0) { |
| return ""; |
| } |
| bytes[last] += 1; |
| return new String(bytes, 0, last + 1, "ISO8859-1"); |
| } catch (UnsupportedEncodingException e) { |
| throw new RuntimeException("JVM must support ISO8859-1 char encoding", e); |
| } |
| } |
| |
| private Util() {} |
| } |