forked from gfwilliams/tiny-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasString.h
63 lines (44 loc) · 1.1 KB
/
asString.h
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
/*
* File: asString.h
* Author: ghernan
*
* AsyncScript string class implementation
*
* Created on January 3, 2017, 2:19 PM
*/
#ifndef ASSTRING_H
#define ASSTRING_H
#pragma once
#include "asObjects.h"
/**
* Javascript string class.
* Javascript strings are immutable. Once created, they cannot be modified.
*/
class JSString : public JSObject
{
public:
static Ref<JSString> create(const std::string& value);
virtual ASValue unFreeze(bool forceClone=false);
virtual bool toBoolean()const
{
return !m_text.empty();
}
virtual double toDouble()const;
virtual std::string toString()const
{
return m_text;
}
virtual ASValue readField(const std::string& key)const;
virtual ASValue getAt(ASValue index);
virtual std::string getJSON(int indent);
virtual double compare (const ASValue& b, ExecutionContext* ec)const;
static Ref<JSClass> StringClass;
protected:
JSString(const std::string& text)
: JSObject(StringClass, MT_DEEPFROZEN), m_text(text)
{
}
private:
const std::string m_text;
};
#endif /* ASSTRING_H */