1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifndef STRING_OBJECT_H_
23#define STRING_OBJECT_H_
24
25#include "function_object.h"
26#include "JSWrapperObject.h"
27#include "internal.h"
28
29namespace KJS {
30
31 class StringInstance : public JSWrapperObject {
32 public:
33 StringInstance(JSObject *proto);
34 StringInstance(JSObject *proto, StringImp*);
35 StringInstance(JSObject *proto, const UString&);
36
37 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
38 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
39
40 using KJS::JSObject::put;
41 virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*, int attr = None);
42 using KJS::JSObject::deleteProperty;
43 virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName);
44 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, PropertyMap::PropertyMode mode);
45 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
46
47 virtual UString toString(ExecState *exec) const;
48 virtual JSObject* valueClone(Interpreter* targetCtx) const;
49
50 virtual const ClassInfo *classInfo() const { return &info; }
51 static const ClassInfo info;
52
53 StringImp* internalValue() const { return static_cast<StringImp*>(JSWrapperObject::internalValue());}
54
55 bool conversionsCustomized() const { return m_conversionsCustomized; }
56 private:
57 bool inlineGetOwnPropertySlot(ExecState*, unsigned, PropertySlot&);
58
59 static JSValue* lengthGetter(ExecState*, JSObject *, const Identifier&, const PropertySlot&);
60 static JSValue* indexGetter(ExecState*, JSObject *, unsigned, const PropertySlot&);
61
62 bool m_conversionsCustomized;
63 };
64
65 /**
66 * @internal
67 *
68 * The initial value of String.prototype (and thus all objects created
69 * with the String constructor
70 */
71 class StringPrototype : public StringInstance {
72 public:
73 StringPrototype(ExecState *exec,
74 ObjectPrototype *objProto);
75 using KJS::StringInstance::getOwnPropertySlot;
76 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
77 virtual const ClassInfo *classInfo() const { return &info; }
78 static const ClassInfo info;
79 };
80
81 /**
82 * @internal
83 *
84 * Class to implement all methods that are properties of the
85 * String.prototype object
86 */
87 class StringProtoFunc : public InternalFunctionImp {
88 public:
89 StringProtoFunc(ExecState *exec, int i, int len, const Identifier&);
90
91 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
92
93 enum { ToString, ValueOf, CharAt, CharCodeAt, Concat, IndexOf, LastIndexOf,
94 Match, Replace, Search, Slice, Split,
95 Substr, Substring, FromCharCode, ToLowerCase, ToUpperCase,
96 ToLocaleLowerCase, ToLocaleUpperCase, Trim, LocaleCompare
97#ifndef KJS_PURE_ECMA
98 , Big, Small, Blink, Bold, Fixed, Italics, Strike, Sub, Sup,
99 Fontcolor, Fontsize, Anchor, Link, TrimLeft, TrimRight
100#endif
101 };
102
103 static void setToLowerFunction(UnicodeSupport::StringConversionFunction f);
104 static void setToUpperFunction(UnicodeSupport::StringConversionFunction f);
105 private:
106 int id;
107 };
108
109 /**
110 * @internal
111 *
112 * The initial value of the global variable's "String" property
113 */
114 class StringObjectImp : public InternalFunctionImp {
115 public:
116 StringObjectImp(ExecState *exec,
117 FunctionPrototype *funcProto,
118 StringPrototype *stringProto);
119
120 virtual bool implementsConstruct() const;
121 using KJS::JSObject::construct;
122 virtual JSObject *construct(ExecState *exec, const List &args);
123 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
124 };
125
126 /**
127 * @internal
128 *
129 * Class to implement all methods that are properties of the
130 * String object
131 */
132 class StringObjectFuncImp : public InternalFunctionImp {
133 public:
134 StringObjectFuncImp(ExecState*, FunctionPrototype*, const Identifier&);
135 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
136 };
137
138} // namespace
139
140#endif
141
142