Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[odd] Line-endings oddness.
  • Loading branch information
jnthn committed Nov 19, 2010
1 parent b930a23 commit 2e58221
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 150 deletions.
50 changes: 25 additions & 25 deletions dotnet/runtime/Runtime/Ops/Metamodel.cs
Expand Up @@ -42,7 +42,7 @@ public static RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT)
/// <param name="Obj"></param>
/// <returns></returns>
public static RakudoObject repr_defined(ThreadContext TC, RakudoObject Obj)
{
{
return Ops.box_int(TC, !(Obj is object) || Obj.STable.REPR.defined(TC, Obj) ? 1 : 0, TC.DefaultBoolBoxType);
}

Expand All @@ -56,18 +56,18 @@ public static RakudoObject repr_defined(ThreadContext TC, RakudoObject Obj)
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, string Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Name);
}

/// <summary>
/// Gets the value of an attribute.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
/// <returns></returns>
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Ops.unbox_str(TC, Name));
}

/// <summary>
/// Gets the value of an attribute.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
/// <returns></returns>
public static RakudoObject get_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name)
{
return Object.STable.REPR.get_attribute(TC, Object, Class, Ops.unbox_str(TC, Name));
}

/// <summary>
Expand All @@ -93,18 +93,18 @@ public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, Raku
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Name, Value);
return Value;
}

/// <summary>
/// Binds the value of an attribute to the given value.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name, RakudoObject Value)
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Ops.unbox_str(TC, Name), Value);
return Value;
}

/// <summary>
/// Binds the value of an attribute to the given value.
/// </summary>
/// <param name="Object"></param>
/// <param name="Class"></param>
/// <param name="Name"></param>
public static RakudoObject bind_attr(ThreadContext TC, RakudoObject Object, RakudoObject Class, RakudoObject Name, RakudoObject Value)
{
Object.STable.REPR.bind_attribute(TC, Object, Class, Ops.unbox_str(TC, Name), Value);
return Value;
}

/// <summary>
Expand Down
250 changes: 125 additions & 125 deletions dotnet/runtime/Runtime/Ops/Primitive.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using System.Text.RegularExpressions;
using Rakudo.Metamodel;
using Rakudo.Metamodel.Representations;
Expand Down Expand Up @@ -215,130 +215,130 @@ public static RakudoObject bitwise_xor_num(ThreadContext TC, RakudoObject x, Rak
public static RakudoObject concat(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_str(TC, Ops.unbox_str(TC, x) + Ops.unbox_str(TC, y), TC.DefaultStrBoxType);
}

/// <summary>
/// Performs a string substring.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject substr(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
return Ops.box_str(TC, z.STable.REPR.defined(TC, z)
? Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y), Ops.unbox_int(TC, z))
: Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y)), TC.DefaultStrBoxType);
}

/// <summary>
/// Performs a string substring.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject substr(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_str(TC, Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y)), TC.DefaultStrBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject index_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_int(TC, Ops.unbox_str(TC, x).IndexOf(Ops.unbox_str(TC, y)), TC.DefaultIntBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not, starting at a specified index.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject index_str_index(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
return Ops.box_int(TC, Ops.unbox_str(TC, x).IndexOf(Ops.unbox_str(TC, y), Ops.unbox_int(TC, z)), TC.DefaultIntBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not, starting at a specified index.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject split_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
RakudoObject list = Ops.instance_of(TC, Ops.get_lex(TC, "NQPList"));
var store = ((P6list.Instance)list).Storage;
foreach (string splitted in Ops.unbox_str(TC, x).Split(Ops.unbox_str(TC, y)[0]))
store.Add(Ops.box_str(TC, splitted, TC.DefaultStrBoxType));
return list;
}

/// <summary>
/// Checks whether a character at a particular index in a string
/// is a member of a particular character class.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject is_cclass_str_index(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
CCLASS cclass = (CCLASS)Enum.Parse(typeof(CCLASS), Ops.unbox_str(TC, x));
string target = Ops.unbox_str(TC, y);
int index = Ops.unbox_int(TC, z);
return Ops.box_int(TC, is_cclass(target, index, cclass) ? 1 : 0, TC.DefaultIntBoxType);
}

/// <summary>
/// Checks whether a character is a member of a particular character class.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject is_cclass_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
CCLASS cclass = (CCLASS)Enum.Parse(typeof(CCLASS), Ops.unbox_str(TC, x));
string target = Ops.unbox_str(TC, y);
return Ops.box_int(TC, is_cclass(target, 0, cclass) ? 1 : 0, TC.DefaultIntBoxType);
}

// see http://msdn.microsoft.com/en-us/library/20bw873z.aspx
// more precisely http://msdn.microsoft.com/en-us/library/20bw873z.aspx#SupportedUnicodeGeneralCategories
// to add more categories/patterns.
enum CCLASS
{
Numeric
}

static Regex NumericCompare = new Regex(@"^\p{N}$", RegexOptions.Compiled);

static bool is_cclass(string target, int index, CCLASS cclass)
{
switch ((int)cclass)
{
case 0:
return NumericCompare.IsMatch(target, index);
default:
throw new NotImplementedException("The character class " + cclass + " is not yet implemented");
}
}

/// <summary>
/// Performs a string substring.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject substr(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
return Ops.box_str(TC, z.STable.REPR.defined(TC, z)
? Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y), Ops.unbox_int(TC, z))
: Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y)), TC.DefaultStrBoxType);
}

/// <summary>
/// Performs a string substring.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject substr(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_str(TC, Ops.unbox_str(TC, x).Substring(Ops.unbox_int(TC, y)), TC.DefaultStrBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject index_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_int(TC, Ops.unbox_str(TC, x).IndexOf(Ops.unbox_str(TC, y)), TC.DefaultIntBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not, starting at a specified index.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject index_str_index(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
return Ops.box_int(TC, Ops.unbox_str(TC, x).IndexOf(Ops.unbox_str(TC, y), Ops.unbox_int(TC, z)), TC.DefaultIntBoxType);
}

/// <summary>
/// Search for the first occurrence of a substring within a string and returns its zero-based index
/// if it's found and -1 if it's not, starting at a specified index.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject split_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
RakudoObject list = Ops.instance_of(TC, Ops.get_lex(TC, "NQPList"));
var store = ((P6list.Instance)list).Storage;
foreach (string splitted in Ops.unbox_str(TC, x).Split(Ops.unbox_str(TC, y)[0]))
store.Add(Ops.box_str(TC, splitted, TC.DefaultStrBoxType));
return list;
}

/// <summary>
/// Checks whether a character at a particular index in a string
/// is a member of a particular character class.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject is_cclass_str_index(ThreadContext TC, RakudoObject x, RakudoObject y, RakudoObject z)
{
CCLASS cclass = (CCLASS)Enum.Parse(typeof(CCLASS), Ops.unbox_str(TC, x));
string target = Ops.unbox_str(TC, y);
int index = Ops.unbox_int(TC, z);
return Ops.box_int(TC, is_cclass(target, index, cclass) ? 1 : 0, TC.DefaultIntBoxType);
}

/// <summary>
/// Checks whether a character is a member of a particular character class.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="ResultType"></param>
/// <returns></returns>
public static RakudoObject is_cclass_str(ThreadContext TC, RakudoObject x, RakudoObject y)
{
CCLASS cclass = (CCLASS)Enum.Parse(typeof(CCLASS), Ops.unbox_str(TC, x));
string target = Ops.unbox_str(TC, y);
return Ops.box_int(TC, is_cclass(target, 0, cclass) ? 1 : 0, TC.DefaultIntBoxType);
}

// see http://msdn.microsoft.com/en-us/library/20bw873z.aspx
// more precisely http://msdn.microsoft.com/en-us/library/20bw873z.aspx#SupportedUnicodeGeneralCategories
// to add more categories/patterns.
enum CCLASS
{
Numeric
}

static Regex NumericCompare = new Regex(@"^\p{N}$", RegexOptions.Compiled);

static bool is_cclass(string target, int index, CCLASS cclass)
{
switch ((int)cclass)
{
case 0:
return NumericCompare.IsMatch(target, index);
default:
throw new NotImplementedException("The character class " + cclass + " is not yet implemented");
}
}
}
}

0 comments on commit 2e58221

Please sign in to comment.