| 1 |
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package com.eprosima.idl.util; |
| 16 |
|
| 17 |
import java.io.File; |
| 18 |
|
| 19 |
public class Util |
| 20 |
{ |
| 21 |
public static String getIDLFileNameOnly(String idlFilename) |
| 22 |
{ |
| 23 |
int index = -1; |
| 24 |
String auxString = idlFilename, returnedValue = null; |
| 25 |
|
| 26 |
index = idlFilename.lastIndexOf(File.separator); |
| 27 |
|
| 28 |
if(index == -1) |
| 29 |
{ |
| 30 |
index = idlFilename.lastIndexOf('/'); |
| 31 |
} |
| 32 |
|
| 33 |
if(index != -1) |
| 34 |
{ |
| 35 |
auxString = idlFilename.substring(index + 1); |
| 36 |
} |
| 37 |
|
| 38 |
// Remove '.idl' |
| 39 |
returnedValue = auxString.substring(0, auxString.length() - 4); |
| 40 |
|
| 41 |
return returnedValue; |
| 42 |
} |
| 43 |
|
| 44 |
public static String getIDLFileOnly(String idlFileURL) |
| 45 |
{ |
| 46 |
int index = -1; |
| 47 |
String returnedValue = null; |
| 48 |
|
| 49 |
index = idlFileURL.lastIndexOf(File.separator); |
| 50 |
|
| 51 |
if(index == -1) |
| 52 |
index = idlFileURL.lastIndexOf('/'); |
| 53 |
|
| 54 |
if(index != -1) |
| 55 |
returnedValue = idlFileURL.substring(index + 1); |
| 56 |
else |
| 57 |
returnedValue = idlFileURL; |
| 58 |
|
| 59 |
return returnedValue; |
| 60 |
} |
| 61 |
|
| 62 |
public static String getIDLFileDirectoryOnly(String idlFileURL) |
| 63 |
{ |
| 64 |
int index = -1; |
| 65 |
String returnedValue = null; |
| 66 |
|
| 67 |
index = idlFileURL.lastIndexOf(File.separator); |
| 68 |
|
| 69 |
if(index == -1) |
| 70 |
index = idlFileURL.lastIndexOf('/'); |
| 71 |
|
| 72 |
if(index != -1) |
| 73 |
returnedValue = idlFileURL.substring(0, index + 1); |
| 74 |
|
| 75 |
return returnedValue; |
| 76 |
} |
| 77 |
|
| 78 |
public static String stringTrimAll(String str) |
| 79 |
{ |
| 80 |
String trimstr = str.replaceAll("\\s+", ""); |
| 81 |
return trimstr; |
| 82 |
} |
| 83 |
} |