0022484: UNICODE characters support
[occt.git] / src / UTL / UTL.cxx
CommitLineData
b311480e 1// Created on: 1997-11-24
2// Created by: Mister rmi
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <UTL.ixx>
18#include <OSD_Host.hxx>
19#include <OSD_Path.hxx>
20#include <TCollection_ExtendedString.hxx>
21#include <TCollection_AsciiString.hxx>
22#include <Resource_Unicode.hxx>
23#include <OSD_Environment.hxx>
24#include <OSD_FileIterator.hxx>
25#include <OSD_File.hxx>
26#include <OSD_Protection.hxx>
27#include <OSD_SingleProtection.hxx>
7fd59977 28
29TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
30 TCollection_ExtendedString x;
31 OSD_Environment theEnv(aCString);
32 TCollection_AsciiString theValue=theEnv.Value();
d9ff84e8 33 if( ! theValue.IsEmpty())
34 x = TCollection_ExtendedString(theValue);
7fd59977 35 return x;
36}
7fd59977 37
d9ff84e8 38TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName)
39{
40 TCollection_AsciiString aFileNameU(aFileName);
41 OSD_Path p = OSD_Path(aFileNameU);
42 TCollection_AsciiString theExtension = p.Extension();
43 if (theExtension.Value(1) == '.')
44 theExtension.Remove(1, 1);
45 return TCollection_ExtendedString(theExtension);
7fd59977 46}
d9ff84e8 47
48Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver,
49 const TCollection_ExtendedString& aFileName,
50 const Storage_OpenMode aMode)
51{
52 return aDriver.Open(TCollection_AsciiString(aFileName),aMode);
7fd59977 53}
54
d9ff84e8 55void UTL::AddToUserInfo(const Handle(Storage_Data)& aData,
56 const TCollection_ExtendedString& anInfo)
57{
58 aData->AddToUserInfo(TCollection_AsciiString(anInfo));
7fd59977 59}
7fd59977 60
d9ff84e8 61OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName)
62{
63 OSD_Path p = OSD_Path(TCollection_AsciiString(aFileName));
7fd59977 64 return p;
65}
d9ff84e8 66
67TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath)
68{
69 return TCollection_ExtendedString(aPath.Disk());
7fd59977 70}
d9ff84e8 71
72TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath)
73{
74 return TCollection_ExtendedString(aPath.Trek());
7fd59977 75}
d9ff84e8 76
77TCollection_ExtendedString UTL::Name(const OSD_Path& aPath)
78{
79 return TCollection_ExtendedString(aPath.Name());
7fd59977 80}
d9ff84e8 81
82TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath)
83{
84 return TCollection_ExtendedString(aPath.Extension());
7fd59977 85}
d9ff84e8 86
87OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask)
88{
89 OSD_FileIterator it = OSD_FileIterator(aPath,TCollection_AsciiString(aMask));
7fd59977 90 return it;
91}
d9ff84e8 92
93TCollection_ExtendedString UTL::LocalHost()
94{
7fd59977 95 OSD_Host h;
d9ff84e8 96 return TCollection_ExtendedString(h.HostName());
7fd59977 97}
d9ff84e8 98
99TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString)
100{
101 return TCollection_ExtendedString(anAsciiString);
7fd59977 102}
d9ff84e8 103
104Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString)
105{
7fd59977 106 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
107}
d9ff84e8 108
109Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager,
110 const TCollection_ExtendedString& aResourceName)
111{
112 return aResourceManager->Find(TCollection_AsciiString(aResourceName).ToCString());
113}
114
115TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager,
116 const TCollection_ExtendedString& aResourceName)
117{
118 TCollection_AsciiString aResourceNameU(aResourceName);
119 return TCollection_ExtendedString(aResourceManager->Value(aResourceNameU.ToCString()),
120 Standard_True);
7fd59977 121}
122
d9ff84e8 123Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString)
124{
125 TCollection_AsciiString a(anExtendedString);
7fd59977 126 return a.IntegerValue();
127}
d9ff84e8 128
129Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString)
130{
7fd59977 131 static TCollection_AsciiString theValue;
d9ff84e8 132 theValue = TCollection_AsciiString(anExtendedString);
7fd59977 133 return theValue.ToCString();
134}
7fd59977 135
d9ff84e8 136Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName)
137{
7fd59977 138 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
139 case OSD_W:
140 case OSD_RW:
141 case OSD_WX:
142 case OSD_RWX:
143 case OSD_RWD:
144 case OSD_WXD:
145 case OSD_RWXD:
146 return Standard_False;
147 default:
148 return Standard_True;
149 }
150}