[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Builtins StringConstructor.c
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Builtins StringConstructor.cs,NONE,1.1 StringObject.cs,NONE,1.1 StringPrototype.cs,NONE,1.1 GlobalObject.cs,1.4,1.5 |
Date: |
Sun, 16 Mar 2003 16:49:58 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/JScript/Builtins
In directory subversions:/tmp/cvs-serv24591/JScript/Builtins
Modified Files:
GlobalObject.cs
Added Files:
StringConstructor.cs StringObject.cs StringPrototype.cs
Log Message:
Begin implementing the JScript "String" class.
--- NEW FILE ---
/*
* StringConstructor.cs - Object that represents the "String constructor.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
using System.Text;
using Microsoft.JScript.Vsa;
public sealed class StringConstructor : ScriptFunction
{
// Constructor.
internal StringConstructor(FunctionPrototype parent)
: base(parent, "String", 1) {}
// Create a new string instance.
[JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
public new StringObject CreateInstance(params Object[] args)
{
return (StringObject)Construct(engine, args);
}
// Invoke the string constructor.
public String Invoke(Object arg)
{
return Convert.ToString(arg);
}
// Build a string from an array of character codes.
[JSFunction(JSFunctionAttributeEnum.HasVarArgs,
JSBuiltin.String_fromCharCode)]
public static String fromCharCode(params Object[] args)
{
StringBuilder builder = new StringBuilder();
foreach(Object obj in args)
{
// TODO - implement Convert.ToChar
//builder.Append(Convert.ToChar(obj));
}
return builder.ToString();
}
// Perform a call on this object.
internal override Object Call
(VsaEngine engine, Object thisob, Object[] args)
{
if(args.Length == 0)
{
return String.Empty;
}
else
{
return Convert.ToString(args[0]);
}
}
// Perform a constructor call on this object.
internal override Object Construct(VsaEngine engine, Object[] args)
{
if(args.Length == 0)
{
return new StringObject
(EngineInstance.GetEngineInstance(engine)
.GetStringPrototype(), String.Empty);
}
else
{
return new StringObject
(EngineInstance.GetEngineInstance(engine)
.GetStringPrototype(),
Convert.ToString(args[0]));
}
}
}; // class StringConstructor
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* StringObject.cs - Implementation of string objects.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
public class StringObject : JSObject
{
// Internal state.
private String value;
// Constructor.
internal StringObject(ScriptObject prototype, String value)
: base(prototype)
{
this.value = value;
}
// Get the length of this string.
public int length
{
get
{
return value.Length;
}
}
// Determine if two string objects are equal.
public override bool Equals(Object obj)
{
if(obj is StringObject)
{
// Unwrap the string object first.
obj = ((StringObject)obj).value;
}
return value.Equals(obj);
}
// Get a hash code for this object.
public override int GetHashCode()
{
return value.GetHashCode();
}
// Get the type code for this object.
public new Type GetType()
{
return typeof(StringObject);
}
// Convert this string object into a raw string.
public override String ToString()
{
return value;
}
// Get the internal "[[Class]]" property for this object.
internal override String Class
{
get
{
return "String";
}
}
// Get the default value for this object.
internal override Object DefaultValue(DefaultValueHint hint)
{
return value;
}
}; // class StringObject
}; // namespace Microsoft.JScript
--- NEW FILE ---
/*
* StringPrototype.cs - Prototype for JScript string objects.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Microsoft.JScript
{
using System;
using System.Text;
using Microsoft.JScript.Vsa;
public class StringPrototype : StringObject
{
// Constructor.
internal StringPrototype(ScriptObject prototype)
: base(prototype, String.Empty)
{
// Add the builtin "String" properties to the
prototype.
EngineInstance inst =
EngineInstance.GetEngineInstance(engine);
Put("constructor", inst.GetStringConstructor());
AddBuiltin(inst, "anchor");
AddBuiltin(inst, "big");
AddBuiltin(inst, "blink");
AddBuiltin(inst, "bold");
AddBuiltin(inst, "fixed");
AddBuiltin(inst, "fontcolor");
AddBuiltin(inst, "fontsize");
AddBuiltin(inst, "charAt");
AddBuiltin(inst, "charCodeAt");
AddBuiltin(inst, "concat");
}
// Get the "String" class constructor. Don't use this.
public static StringConstructor constructor
{
get
{
return
EngineInstance.Default.GetStringConstructor();
}
}
// Get the character at a particular position in a string.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_charAt)]
public static String charAt(Object thisob, double pos)
{
// TODO
return null;
}
// Get the character code at a particular position in a string.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_charCodeAt)]
public static Object charCodeAt(Object thisob, double pos)
{
// TODO
return null;
}
// Concatenate strings.
[JSFunction(JSFunctionAttributeEnum.HasThisObject |
JSFunctionAttributeEnum.HasVarArgs,
JSBuiltin.String_concat)]
public static String concat(Object thisob, params Object[] args)
{
StringBuilder builder = new StringBuilder();
builder.Append(Convert.ToString(thisob));
foreach(Object obj in args)
{
builder.Append(Convert.ToString(obj));
}
return builder.ToString();
}
// Build a HTML anchor tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_anchor)]
public static String anchor(Object thisob, Object anchorName)
{
return "<A NAME=\"" +
Convert.ToString(anchorName) +
"\">" + Convert.ToString(thisob) +
"</A>";
}
// Build a HTML "big" tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_big)]
public static String big(Object thisob)
{
return "<BIG>" + Convert.ToString(thisob) +
"</BIG>";
}
// Build a HTML "blink" tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_blink)]
public static String blink(Object thisob)
{
return "<BLINK>" + Convert.ToString(thisob) +
"</BLINK>";
}
// Build a HTML "bold" tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_bold)]
public static String bold(Object thisob)
{
return "<B>" + Convert.ToString(thisob) +
"</B>";
}
// Build a HTML "tt" tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_fixed)]
public static String @fixed(Object thisob)
{
return "<TT>" + Convert.ToString(thisob) +
"</TT>";
}
// Build a HTML font color tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_fontcolor)]
public static String fontcolor(Object thisob, Object colorName)
{
return "<FONT COLOR=\"" +
Convert.ToString(colorName) +
"\">" + Convert.ToString(thisob) +
"</FONT>";
}
// Build a HTML font size tag.
[JSFunction(JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.String_fontsize)]
public static String fontsize(Object thisob, Object fontSize)
{
return "<FONT SIZE=\"" +
Convert.ToString(fontSize) +
"\">" + Convert.ToString(thisob) +
"</FONT>";
}
}; // class StringPrototype
// "Lenient" version of the above class which exports all of the
// prototype's properties to the user level.
public class LenientStringPrototype : StringPrototype
{
// Accessible properties.
public new Object constructor;
public new Object charAt;
public new Object charCodeAt;
public new Object concat;
public new Object anchor;
public new Object big;
public new Object blink;
public new Object bold;
public new Object @fixed;
public new Object fontcolor;
public new Object fontsize;
// Constructor.
internal LenientStringPrototype(ScriptObject prototype)
: base(prototype)
{
constructor = Get("constructor");
charAt = Get("charAt");
charCodeAt = Get("charCodeAt");
concat = Get("concat");
anchor = Get("anchor");
big = Get("big");
blink = Get("blink");
bold = Get("bold");
@fixed = Get("fixed");
fontcolor = Get("fontcolor");
fontsize = Get("fontsize");
}
}; // class LenientStringPrototype
}; // namespace Microsoft.JScript
Index: GlobalObject.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Builtins/GlobalObject.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** GlobalObject.cs 6 Mar 2003 23:52:40 -0000 1.4
--- GlobalObject.cs 16 Mar 2003 21:49:40 -0000 1.5
***************
*** 93,97 ****
--- 93,99 ----
AddProperty("ReferenceError", ReferenceError);
AddProperty("RegExp", RegExp);
+ #endif
AddProperty("String", String);
+ #if false
AddProperty("SyntaxError", SyntaxError);
AddProperty("TypeError", TypeError);
***************
*** 224,234 ****
}
}
public static StringConstructor String
{
get
{
! return StringConstructor.constructor;
}
}
public static ErrorConstructor SyntaxError
{
--- 226,238 ----
}
}
+ #endif
public static StringConstructor String
{
get
{
! return
EngineInstance.Default.GetStringConstructor();
}
}
+ #if false
public static ErrorConstructor SyntaxError
{
***************
*** 383,387 ****
// Parse the rest of a UTF-8 sequence within an encoded URI.
! private static int ParseRestOfUTF8(int utf8, String uri, ref int _index)
{
int index = _index;
--- 387,391 ----
// Parse the rest of a UTF-8 sequence within an encoded URI.
! private static int ParseRestOfUTF8(int utf8, string uri, ref int _index)
{
int index = _index;
***************
*** 519,523 ****
// Hexadecimal characters for URI encoding.
! private const String hex = "0123456789ABCDEF";
// Append a hex sequence to a string builder.
--- 523,527 ----
// Hexadecimal characters for URI encoding.
! private const string hex = "0123456789ABCDEF";
// Append a hex sequence to a string builder.
***************
*** 616,620 ****
public static string escape(object str)
{
! String s = Convert.ToString(str);
StringBuilder builder = new
StringBuilder(s.Length);
foreach(char ch in s)
--- 620,624 ----
public static string escape(object str)
{
! string s = Convert.ToString(str);
StringBuilder builder = new
StringBuilder(s.Length);
foreach(char ch in s)
***************
*** 675,679 ****
public static double parseFloat(object str)
{
! String s = Convert.ToString(str);
int index = 0;
int start;
--- 679,683 ----
public static double parseFloat(object str)
{
! string s = Convert.ToString(str);
int index = 0;
int start;
***************
*** 688,702 ****
// Check for infinities.
if((s.Length - index) >= 8 &&
! String.Compare(s, index, "Infinity", 0, 8)
== 0)
{
return Double.PositiveInfinity;
}
if((s.Length - index) >= 9 &&
! String.Compare(s, index, "-Infinity", 0, 9)
== 0)
{
return Double.NegativeInfinity;
}
if((s.Length - index) >= 9 &&
! String.Compare(s, index, "+Infinity", 0, 9)
== 0)
{
return Double.PositiveInfinity;
--- 692,706 ----
// Check for infinities.
if((s.Length - index) >= 8 &&
! string.Compare(s, index, "Infinity", 0, 8)
== 0)
{
return Double.PositiveInfinity;
}
if((s.Length - index) >= 9 &&
! string.Compare(s, index, "-Infinity", 0, 9)
== 0)
{
return Double.NegativeInfinity;
}
if((s.Length - index) >= 9 &&
! string.Compare(s, index, "+Infinity", 0, 9)
== 0)
{
return Double.PositiveInfinity;
***************
*** 781,785 ****
public static double parseInt(object str, object radix)
{
! String s = Convert.ToString(str);
int r = Convert.ToInt32(radix);
int index = 0;
--- 785,789 ----
public static double parseInt(object str, object radix)
{
! string s = Convert.ToString(str);
int r = Convert.ToInt32(radix);
int index = 0;
***************
*** 910,914 ****
public static string unescape(object str)
{
! String s = Convert.ToString(str);
StringBuilder builder = new
StringBuilder(s.Length);
int index = 0;
--- 914,918 ----
public static string unescape(object str)
{
! string s = Convert.ToString(str);
StringBuilder builder = new
StringBuilder(s.Length);
int index = 0;
***************
*** 1062,1065 ****
--- 1066,1070 ----
}
}
+ #endif
private object array;
public new object Array
***************
*** 1072,1076 ****
array is Missing)
{
! array =
GlobalObject.Array;
}
return array;
--- 1077,1082 ----
array is Missing)
{
! array =
EngineInstance.GetEngineInstance
!
(engine).GetArrayConstructor();
}
return array;
***************
*** 1085,1088 ****
--- 1091,1095 ----
}
}
+ #if false
private object booleanConstructor;
public new object Boolean
***************
*** 1368,1371 ****
--- 1375,1379 ----
}
}
+ #endif
private object stringConstructor;
public new object String
***************
*** 1378,1382 ****
stringConstructor is Missing)
{
! stringConstructor =
GlobalObject.String;
}
return stringConstructor;
--- 1386,1392 ----
stringConstructor is Missing)
{
! stringConstructor =
!
EngineInstance.GetEngineInstance
!
(engine).GetStringConstructor();
}
return stringConstructor;
***************
*** 1391,1394 ****
--- 1401,1405 ----
}
}
+ #if false
private object syntaxError;
public new object SyntaxError
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Builtins StringConstructor.cs,NONE,1.1 StringObject.cs,NONE,1.1 StringPrototype.cs,NONE,1.1 GlobalObject.cs,1.4,1.5,
Rhys Weatherley <address@hidden> <=