1 /**
2  *  ServingXML
3  *
4  *  Copyright (C) 2006  Daniel Parker
5  *    daniel.parker@servingxml.com
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  **/
20 
21 package com.servingxml.util;
22 
23 public class CharArrayHelper {
24 
startsWith(char[] buffer, int start, int length, char[] value)25   public final static int startsWith(char[] buffer, int start, int length, char[] value) {
26     int index = 0;
27 
28     boolean found = false;
29     if (value.length > 0 && (length - value.length) >= 0) {
30       found = true;
31       for (int i = 0; found && i < value.length; ++i) {
32         if (value[i] != buffer[start+i]) {
33           found = false;
34         }
35       }
36     }
37 
38     return found ? value.length : 0;
39   }
40 
startsWith(char[] buffer, int start, int length, String value)41   public final static int startsWith(char[] buffer, int start, int length, String value) {
42     int index = 0;
43 
44     boolean found = false;
45     if (value.length() > 0 && (length - value.length()) > 0) {
46       found = true;
47       for (int i = 0; found && i < value.length(); ++i) {
48         if (value.charAt(i) != buffer[start+i]) {
49           found = false;
50         }
51       }
52     }
53 
54     return found ? value.length() : 0;
55   }
56 }
57