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 private static final String[] EMPTY = new String[0];
36 public static String[] split(char c, String value) {
41 return split(c,value,0,value.length());
44 public static String[] split(char c, String value, int start, int end) {
49 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
51 for (count=1,idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,++idx),++count);
52 String[] rv = new String[count];
54 rv[0]=value.substring(start,end);
58 for (idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,idx)) {
59 rv[++count]=value.substring(last,idx);
62 rv[++count]=value.substring(last,end);
67 public static String[] splitTrim(char c, String value, int start, int end) {
72 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
74 for (count=1,idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,++idx),++count);
75 String[] rv = new String[count];
77 rv[0]=value.substring(start,end).trim();
81 for (idx=value.indexOf(c,start);idx>=0 && idx<end;idx=value.indexOf(c,idx)) {
82 rv[++count]=value.substring(last,idx).trim();
85 rv[++count]=value.substring(last,end).trim();
90 public static String[] splitTrim(char c, String value) {
94 return splitTrim(c,value,0,value.length());
97 public static String[] splitTrim(char c, String value, int size) {
103 String[] rv = new String[size];
110 for (idx=value.indexOf(c);idx>=0 && count<size;idx=value.indexOf(c,idx)) {
111 rv[++count]=value.substring(last,idx).trim();
115 rv[++count]=value.substring(last,idx).trim();
117 rv[++count]=value.substring(last).trim();