2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi.util;
25 * Split by Char, optional Trim
27 * Note: Copied from Inno to avoid linking issues.
28 * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character
34 public static String[] split(char c, String value) {
35 return split(c,value,0,value.length());
38 public static String[] split(char c, String value, int start, int end) {
43 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
45 for(count=1,idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,++idx),++count);
46 String[] rv = new String[count];
48 rv[0]=value.substring(start,end);
52 for(idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,idx)) {
53 rv[++count]=value.substring(last,idx);
56 rv[++count]=value.substring(last,end);
61 public static String[] splitTrim(char c, String value, int start, int end) {
66 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
68 for(count=1,idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,++idx),++count);
69 String[] rv = new String[count];
71 rv[0]=value.substring(start,end).trim();
75 for(idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,idx)) {
76 rv[++count]=value.substring(last,idx).trim();
79 rv[++count]=value.substring(last,end).trim();
84 public static String[] splitTrim(char c, String value) {
85 return splitTrim(c,value,0,value.length());
88 public static String[] splitTrim(char c, String value, int size) {
94 String[] rv = new String[size];
101 for(idx=value.indexOf(c);idx>=0 && count<size;idx=value.indexOf(c,idx)) {
102 rv[++count]=value.substring(last,idx).trim();
106 rv[++count]=value.substring(last,idx).trim();
108 rv[++count]=value.substring(last).trim();