1 // Created on: 1997-11-24
2 // Created by: Mister rmi
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <OSD_Environment.hxx>
19 #include <OSD_File.hxx>
20 #include <OSD_FileIterator.hxx>
21 #include <OSD_Host.hxx>
22 #include <OSD_Path.hxx>
23 #include <OSD_Protection.hxx>
24 #include <OSD_SingleProtection.hxx>
25 #include <Resource_Manager.hxx>
26 #include <Resource_Unicode.hxx>
27 #include <Standard_GUID.hxx>
28 #include <Storage_BaseDriver.hxx>
29 #include <Storage_Data.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TCollection_ExtendedString.hxx>
34 TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
35 TCollection_ExtendedString x;
36 OSD_Environment theEnv(aCString);
37 TCollection_AsciiString theValue=theEnv.Value();
38 if( ! theValue.IsEmpty())
39 x = TCollection_ExtendedString(theValue);
43 TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName)
45 TCollection_AsciiString aFileNameU(aFileName);
46 OSD_Path p = OSD_Path(aFileNameU);
47 TCollection_AsciiString theExtension = p.Extension();
48 if (theExtension.Value(1) == '.')
49 theExtension.Remove(1, 1);
50 return TCollection_ExtendedString(theExtension);
53 Storage_Error UTL::OpenFile(const Handle(Storage_BaseDriver)& aDriver,
54 const TCollection_ExtendedString& aFileName,
55 const Storage_OpenMode aMode)
57 return aDriver->Open(TCollection_AsciiString(aFileName),aMode);
60 void UTL::AddToUserInfo(const Handle(Storage_Data)& aData,
61 const TCollection_ExtendedString& anInfo)
63 aData->AddToUserInfo(TCollection_AsciiString(anInfo));
66 OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName)
68 OSD_Path p = OSD_Path(TCollection_AsciiString(aFileName));
72 TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath)
74 return TCollection_ExtendedString(aPath.Disk());
77 TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath)
79 return TCollection_ExtendedString(aPath.Trek());
82 TCollection_ExtendedString UTL::Name(const OSD_Path& aPath)
84 return TCollection_ExtendedString(aPath.Name());
87 TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath)
89 return TCollection_ExtendedString(aPath.Extension());
92 OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask)
94 OSD_FileIterator it = OSD_FileIterator(aPath,TCollection_AsciiString(aMask));
98 TCollection_ExtendedString UTL::LocalHost()
101 return TCollection_ExtendedString(h.HostName());
104 TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString)
106 return TCollection_ExtendedString(anAsciiString);
109 Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString)
111 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
114 Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager,
115 const TCollection_ExtendedString& aResourceName)
117 return aResourceManager->Find(TCollection_AsciiString(aResourceName).ToCString());
120 TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager,
121 const TCollection_ExtendedString& aResourceName)
123 TCollection_AsciiString aResourceNameU(aResourceName);
124 return TCollection_ExtendedString(aResourceManager->Value(aResourceNameU.ToCString()),
128 Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString)
130 TCollection_AsciiString a(anExtendedString);
131 return a.IntegerValue();
134 Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString)
136 static TCollection_AsciiString theValue;
137 theValue = TCollection_AsciiString(anExtendedString);
138 return theValue.ToCString();
141 Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName)
143 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
151 return Standard_False;
153 return Standard_True;