]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/strings/FileNameUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / strings / FileNameUtils.java
index a9c53a4b6070774318303aee6497ee946b9d60ea..d85c250ee01bdc61d6d5208616d1bbdc4a22216b 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-/*\r
- * Created on Jan 21, 2005\r
- * \r
- * Copyright Toni Kalajainen\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.simantics.utils.strings;\r
-\r
-import java.io.File;\r
-\r
-/**\r
- * @author Toni Kalajainen\r
- * \r
- */\r
-public class FileNameUtils {\r
-\r
-    /**\r
-     * Creates directories\r
-     * @param path\r
-     */\r
-    public static void forcePath(String path) {\r
-        // Create directories\r
-        (new File(path)).mkdirs();\r
-    }\r
-\r
-    public static void deleteFile(String filename) {\r
-        (new File(filename)).delete();\r
-    }\r
-\r
-    /**\r
-     * Extracts file's directory Excludes last / \\r
-     * \r
-     * @param filename\r
-     *            the file\r
-     * @return the path\r
-     */\r
-    public static String extractFileDir(String filename) {\r
-        // construct directory name\r
-        String splitted[] = filename.replaceAll("\\\\", "/").split("/");\r
-        if (splitted.length > 1)\r
-            return filename.substring(0, filename.length()\r
-                    - splitted[splitted.length - 1].length() - 1);\r
-        return "";\r
-    }\r
-\r
-    /**\r
-     * Extracts file's name\r
-     * \r
-     * @param path\r
-     *            the path\r
-     * @return the filename\r
-     */\r
-    public static String extractFileName(String path) {\r
-        // construct directory name\r
-        String splitted[] = path.replaceAll("\\\\", "/").split("/");\r
-        if (splitted.length > 1)\r
-            return splitted[splitted.length-1];\r
-        return path;\r
-    }\r
-\r
-    /**\r
-     * Extracts file's name before dot\r
-     * \r
-     * @param filename\r
-     *            the file name\r
-     * @return the name\r
-     */\r
-    public static String extractFilePreDot(String filename) {\r
-        // construct directory name\r
-        String splitted[] = filename.split("\\.");\r
-        if (splitted.length > 1)\r
-            return filename.substring(0, filename.length()\r
-                    - splitted[splitted.length - 1].length() - 1);\r
-        return filename;\r
-    }\r
-\r
-\r
-    /**\r
-     * Extracts file's extension\r
-     * \r
-     * @param filename\r
-     *            the file name\r
-     * @return the name\r
-     */\r
-    public static String extractFileExt(String filename) {\r
-        // construct directory name\r
-        String splitted[] = filename.split("\\.");\r
-        if (splitted.length > 1)\r
-            return splitted[splitted.length-1];\r
-        return "";\r
-    }\r
-\r
-    /**\r
-     * Extracts file's directory Ixcludes last / \\r
-     * \r
-     * @param filename\r
-     *            the file\r
-     * @return the path\r
-     */\r
-    public static String extractFilePath(String filename) {\r
-        // construct directory name\r
-        String splitted[] = filename.replaceAll("\\\\", "/").split("/");\r
-        if (splitted.length > 1)\r
-            return filename.substring(0, filename.length()\r
-                    - splitted[splitted.length - 1].length());\r
-        return "";\r
-    }\r
-\r
-    public static void main(String[] args) {\r
-        System.out.println(extractFileDir("c:\\jees/pox/file.dat"));\r
-        System.out.println(extractFilePath("c:\\jees/pox/file.dat"));\r
-        System.out.println(extractFileName("c:\\jees/pox/file.dat"));\r
-        System.out.println(extractFilePreDot("c:\\jees/pox/file.dat"));\r
-        System.out.println(extractFileExt("c:\\jees/pox/file.dat"));\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+/*
+ * Created on Jan 21, 2005
+ * 
+ * Copyright Toni Kalajainen
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.simantics.utils.strings;
+
+import java.io.File;
+
+/**
+ * @author Toni Kalajainen
+ * 
+ */
+public class FileNameUtils {
+
+    /**
+     * Creates directories
+     * @param path
+     */
+    public static void forcePath(String path) {
+        // Create directories
+        (new File(path)).mkdirs();
+    }
+
+    public static void deleteFile(String filename) {
+        (new File(filename)).delete();
+    }
+
+    /**
+     * Extracts file's directory Excludes last / \
+     * 
+     * @param filename
+     *            the file
+     * @return the path
+     */
+    public static String extractFileDir(String filename) {
+        // construct directory name
+        String splitted[] = filename.replaceAll("\\\\", "/").split("/");
+        if (splitted.length > 1)
+            return filename.substring(0, filename.length()
+                    - splitted[splitted.length - 1].length() - 1);
+        return "";
+    }
+
+    /**
+     * Extracts file's name
+     * 
+     * @param path
+     *            the path
+     * @return the filename
+     */
+    public static String extractFileName(String path) {
+        // construct directory name
+        String splitted[] = path.replaceAll("\\\\", "/").split("/");
+        if (splitted.length > 1)
+            return splitted[splitted.length-1];
+        return path;
+    }
+
+    /**
+     * Extracts file's name before dot
+     * 
+     * @param filename
+     *            the file name
+     * @return the name
+     */
+    public static String extractFilePreDot(String filename) {
+        // construct directory name
+        String splitted[] = filename.split("\\.");
+        if (splitted.length > 1)
+            return filename.substring(0, filename.length()
+                    - splitted[splitted.length - 1].length() - 1);
+        return filename;
+    }
+
+
+    /**
+     * Extracts file's extension
+     * 
+     * @param filename
+     *            the file name
+     * @return the name
+     */
+    public static String extractFileExt(String filename) {
+        // construct directory name
+        String splitted[] = filename.split("\\.");
+        if (splitted.length > 1)
+            return splitted[splitted.length-1];
+        return "";
+    }
+
+    /**
+     * Extracts file's directory Ixcludes last / \
+     * 
+     * @param filename
+     *            the file
+     * @return the path
+     */
+    public static String extractFilePath(String filename) {
+        // construct directory name
+        String splitted[] = filename.replaceAll("\\\\", "/").split("/");
+        if (splitted.length > 1)
+            return filename.substring(0, filename.length()
+                    - splitted[splitted.length - 1].length());
+        return "";
+    }
+
+    public static void main(String[] args) {
+        System.out.println(extractFileDir("c:\\jees/pox/file.dat"));
+        System.out.println(extractFilePath("c:\\jees/pox/file.dat"));
+        System.out.println(extractFileName("c:\\jees/pox/file.dat"));
+        System.out.println(extractFilePreDot("c:\\jees/pox/file.dat"));
+        System.out.println(extractFileExt("c:\\jees/pox/file.dat"));
+    }
+
+}