-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
String.inl
67 lines (56 loc) · 1.28 KB
/
String.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
inline String::String(std::shared_ptr<SharedString>&& sharedString) :
m_sharedString(std::move(sharedString))
{
}
inline void String::ReleaseString()
{
m_sharedString = std::move(GetEmptyString());
}
inline String::SharedString::SharedString() : // Special case: empty string
capacity(0),
size(0)
{
}
inline String::SharedString::SharedString(unsigned int strSize) :
capacity(strSize),
size(strSize),
string(new char[strSize + 1])
{
string[strSize] = '\0';
}
inline String::SharedString::SharedString(unsigned int strSize, unsigned int strCapacity) :
capacity(strCapacity),
size(strSize),
string(new char[strCapacity + 1])
{
string[strSize] = '\0';
}
}
namespace std
{
template<>
struct hash<Nz::String>
{
size_t operator()(const Nz::String& str) const
{
// Algorithme DJB2
// http://www.cse.yorku.ca/~oz/hash.html
size_t h = 5381;
if (!str.IsEmpty())
{
const char* ptr = str.GetConstBuffer();
do
h = ((h << 5) + h) + *ptr;
while (*++ptr);
}
return h;
}
};
}
#include <Nazara/Core/DebugOff.hpp>