Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/StringManipulator.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package Utilities;
23
24
/**
25
* @author Matthew Kilner
26
*/
27
public class StringManipulator {
28
29
public String getStringElement(int elementIndex, String string){
30
31
char seperator = ',';
32
int currentElement = -1;
33
int startIndex = 0;
34
int endIndex = 0;
35
int currentIndex = 0;
36
String element = "";
37
38
while(currentElement != elementIndex){
39
startIndex = currentIndex;
40
endIndex = string.indexOf(seperator, currentIndex);
41
if(endIndex == -1){
42
element = string.substring(currentIndex);
43
} else {
44
currentIndex = endIndex + 1;
45
element = string.substring(startIndex, endIndex);
46
}
47
currentElement += 1;
48
}
49
return element;
50
}
51
52
public static String extractDummyNameSuffix(String string)
53
{
54
char seperator = '/';
55
int startIndex = 0;
56
String suffix = "";
57
58
int lastIndex = string.lastIndexOf(seperator);
59
for(int currentIndex = 0; currentIndex < lastIndex; currentIndex = string.indexOf(seperator, startIndex)){
60
startIndex = currentIndex + 1;
61
}
62
suffix = string.substring(startIndex, lastIndex);
63
64
return suffix.length() == 0 ? null : suffix;
65
}
66
67
public static String extractJarDummyNameSuffix(String string)
68
{
69
char seperator = '/';
70
char pling = '!';
71
int startIndex = 0;
72
String suffix = "";
73
74
int plingIndex = string.lastIndexOf(pling);
75
String tempString = string.substring(startIndex, plingIndex);
76
int lastIndex = tempString.lastIndexOf(seperator);
77
for(int currentIndex = 0; currentIndex < lastIndex; currentIndex = tempString.indexOf(seperator, startIndex)){
78
startIndex = currentIndex + 1;
79
}
80
suffix = tempString.substring(startIndex, lastIndex);
81
82
return suffix.length() == 0 ? null : suffix;
83
}
84
85
}
86
87