0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TDocStd / TDocStd_PathParser.cxx
1 // Created on: 1999-09-17
2 // Created by: Denis PASCAL
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TDocStd_PathParser.hxx>
18
19 #include <TCollection_ExtendedString.hxx>
20
21 TDocStd_PathParser::TDocStd_PathParser(const TCollection_ExtendedString& path)
22 {
23         myPath = path;
24         Parse();
25 }
26
27 void TDocStd_PathParser::Parse()
28 {
29         TCollection_ExtendedString temp = myPath;
30         Standard_Integer PointPosition = myPath.SearchFromEnd(TCollection_ExtendedString("."));
31         if (PointPosition>0)
32                 myExtension = temp.Split(PointPosition);
33         else
34                 return;
35         temp.Trunc(PointPosition-1);
36         Standard_Boolean isFileName = (temp.Length()) ? Standard_True : Standard_False;
37         Standard_Boolean isTrek = Standard_True;
38 #ifdef _WIN32
39         PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("\\"));
40         if (!(PointPosition>0))
41                 PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("/"));
42         if (PointPosition >0) 
43           myName = temp.Split(PointPosition);
44         else {
45           if(isFileName) {
46             myName = temp;
47             isTrek = Standard_False;}
48           else
49             return;
50         }
51 #else
52         PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("/"));
53         if (PointPosition >0) 
54           myName = temp.Split(PointPosition);
55         else {
56           if(isFileName) {
57             myName = temp;
58             isTrek = Standard_False;}
59           else
60             return;
61         }
62 #endif //_WIN32
63         if(isTrek) {
64           temp.Trunc(PointPosition-1);
65           myTrek = temp;
66         } else 
67 #ifdef _WIN32
68           myTrek = ".\\";
69 #else
70         myTrek = "./";
71 #endif 
72 }
73
74
75 TCollection_ExtendedString TDocStd_PathParser::Extension() const
76 {
77         return myExtension;
78 }
79
80 TCollection_ExtendedString TDocStd_PathParser::Name() const
81 {
82         return myName;
83 }
84
85 TCollection_ExtendedString TDocStd_PathParser::Trek() const
86 {
87         return myTrek;
88 }
89
90 TCollection_ExtendedString TDocStd_PathParser::Path() const
91 {
92         return myPath;
93 }
94
95
96 Standard_Integer TDocStd_PathParser::Length() const
97 {
98         return myPath.Length();
99 }