Stroika Library
3.0d16
Help-Home
Loading...
Searching...
No Matches
PathName.cpp
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#include "Stroika/Foundation/StroikaPreComp.h"
5
6
#include "
Stroika/Foundation/Characters/String.h
"
7
#include "
Stroika/Foundation/Characters/StringBuilder.h
"
8
#include "
Stroika/Foundation/Memory/StackBuffer.h
"
9
10
#include "
PathName.h
"
11
12
using namespace
Stroika::Foundation
;
13
using namespace
Stroika::Foundation::Characters
;
14
using namespace
Stroika::Foundation::IO;
15
using namespace
Stroika::Foundation::IO::FileSystem
;
16
17
using
Memory::StackBuffer
;
18
19
/*
20
********************************************************************************
21
************** FileSystem::AssureDirectoryPathSlashTerminated ******************
22
********************************************************************************
23
*/
24
String
FileSystem::AssureDirectoryPathSlashTerminated
(
const
String
& dirPath)
25
{
26
if
(dirPath.empty ()) {
27
AssertNotReached
();
// not sure if this is an error or not. Not sure how code used.
28
// put assert in there to find out... Probably should THROW!
29
// -- LGP 2009-05-12
30
return
String
{filesystem::path::preferred_separator};
31
}
32
else
{
33
Character
lastChar = dirPath[dirPath.
size
() - 1];
34
if
(lastChar == filesystem::path::preferred_separator) {
35
return
dirPath;
36
}
37
StringBuilder
result = dirPath;
38
result += filesystem::path::preferred_separator;
39
return
result;
40
}
41
}
42
43
/*
44
********************************************************************************
45
*********************** FileSystem::SafeFilenameChars **************************
46
********************************************************************************
47
*/
48
String
FileSystem::SafeFilenameChars
(
const
String
& s)
49
{
50
// analyze as wide-char string so we don't mis-identify characters (by looking at lead bytes etc)
51
wstring tmp = s.
As
<wstring> ();
52
Again:
53
for
(
auto
i = tmp.begin (); i != tmp.end (); ++i) {
54
switch
(*i) {
55
case
'\\'
:
56
*i =
'_'
;
57
break
;
58
case
'/'
:
59
*i =
'_'
;
60
break
;
61
case
':'
:
62
*i =
' '
;
63
break
;
64
case
'.'
:
65
tmp.erase (i);
66
goto
Again;
67
}
68
}
69
return
tmp;
70
}
71
72
/*
73
********************************************************************************
74
********************* FileSystem::AssureLongFileName ***************************
75
********************************************************************************
76
*/
77
String
FileSystem::AssureLongFileName
(
const
String
& fileName)
78
{
79
#if qStroika_Foundation_Common_Platform_Windows
80
DWORD r = ::GetLongPathNameW (fileName.
As
<wstring> ().c_str (),
nullptr
, 0);
81
if
(r != 0) {
82
StackBuffer<wchar_t> buf{Memory::eUninitialized, r};
83
r = ::GetLongPathNameW (fileName.
As
<wstring> ().c_str (), buf.data (), r);
84
if
(r != 0) {
85
return
static_cast<
const
wchar_t
*
>
(buf);
86
}
87
}
88
#endif
89
return
fileName;
90
}
AssertNotReached
#define AssertNotReached()
Definition
Assertions.h:355
PathName.h
StackBuffer.h
String.h
StringBuilder.h
Stroika::Foundation::Characters::Character
Definition
Character.h:218
Stroika::Foundation::Characters::StringBuilder
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
Definition
StringBuilder.h:71
Stroika::Foundation::Characters::String
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition
String.h:201
Stroika::Foundation::Characters::String::size
nonvirtual size_t size() const noexcept
Definition
String.inl:534
Stroika::Foundation::Characters::String::As
nonvirtual T As() const
Stroika::Foundation::Memory::InlineBuffer
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
Definition
InlineBuffer.h:90
Stroika::Foundation::Characters
Definition
Character.h:31
Stroika::Foundation::IO::FileSystem
Definition
Foundation/IO/FileSystem/Common.h:18
Stroika::Foundation::IO::FileSystem::SafeFilenameChars
String SafeFilenameChars(const String &s)
Definition
PathName.cpp:48
Stroika::Foundation::IO::FileSystem::AssureLongFileName
String AssureLongFileName(const String &fileName)
Definition
PathName.cpp:77
Stroika::Foundation::IO::FileSystem::AssureDirectoryPathSlashTerminated
String AssureDirectoryPathSlashTerminated(const String &dirPath)
Definition
PathName.cpp:24
Stroika::Foundation
Definition
BloomFilter.h:22
Library
Sources
Stroika
Foundation
IO
FileSystem
PathName.cpp
Generated by
1.9.8