-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstringref.hpp
More file actions
37 lines (29 loc) · 1.18 KB
/
Copy pathstringref.hpp
File metadata and controls
37 lines (29 loc) · 1.18 KB
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
#pragma once
#ifndef STRINGREF_HPP_WZKLOJFK
#define STRINGREF_HPP_WZKLOJFK
#include <string.h>
#include "assert.hpp"
#include "enumerable.hpp"
#include "string_enumerator.hpp"
namespace ftl {
class String;
class StringRef : public Enumerable<StringRef, StringEnumerator> {
public:
typedef StringEnumerator Enumerator;
StringRef() : _data(NULL), _length(0) {}
StringRef(const char* cstr);
StringRef(const char* cstr, size_t len) : _data(cstr), _length(len) {}
StringRef(const StringRef& other) : _data(other._data), _length(other._length) {}
StringRef(const String& other); // definition in string.hpp
StringRef& operator=(const StringRef& other) { _data = other._data; _length = other._length; return *this; }
size_t length() const { return _length; }
char operator[](size_t idx) const { FTL_ASSERT(idx < _length); return _data[idx]; }
const char* c_str() const { return _data; }
StringEnumerator get_enumerator() const { return StringEnumerator(_data, _length); }
private:
const char* _data;
size_t _length;
};
inline StringRef::StringRef(const char* cstr) : _data(cstr), _length(strlen(cstr)) {}
}
#endif /* end of include guard: STRINGREF_HPP_WZKLOJFK */