1 /**
2 This module implements ScriptString. However, host applications should work with D strings by converting
3 the ScriptAny directly to string with toString().
4 
5 ────────────────────────────────────────────────────────────────────────────────
6 
7 Copyright (C) 2021 pillager86.rf.gd
8 
9 This program is free software: you can redistribute it and/or modify it under 
10 the terms of the GNU General Public License as published by the Free Software 
11 Foundation, either version 3 of the License, or (at your option) any later 
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License along with 
19 this program.  If not, see <https://www.gnu.org/licenses/>.
20 */
21 module mildew.types..string;
22 
23 import mildew.types.object;
24 
25 /**
26  * Encapsulates a string. It is stored internally as UTF-8 and treated as such
27  * except during iteration, in which dchar code points are the iteration element.
28  */
29 class ScriptString : ScriptObject
30 {
31     import std.conv: to;
32     import mildew.types.any: ScriptAny;
33 public:
34     /**
35      * Constructs a new ScriptString out of a UTF-8 D string
36      */
37     this(in string str)
38     {
39         import mildew.types.bindings: getStringPrototype;
40         super("string", getStringPrototype, null);
41         _string = str;
42     }
43 
44     /**
45      * Returns the actual D string contained
46      */
47     override string toString() const
48     {
49         return _string;
50     }
51 
52     // methods to bind
53 
54 private:
55     string _string;
56 }