/* RubyString.pmc
 *  Copyright (C) 2001-2003, The Perl Foundation.
 *  SVN Info
 *     $Id: rubystring.pmc 17096 2007-02-20 20:20:48Z paultcochrane $
 *  Overview:
 *     These are the vtable functions for the RubyString base class
 *  Data Structure and Algorithms:
 *  History:
 *  Notes:
 *     Please remove unneeded entries.
 *  References:
 */

#include "parrot/parrot.h"

static STRING *true, *false, *yes, *no;

pmclass RubyString
        extends String
        does string
        dynpmc
        group ruby_group
        hll Ruby
        maps String
{
    void class_init () {
        PMC *string_anchor;
        INTVAL fixedstringarray_typenum;
        if (pass) {
            true  = string_from_const_cstring(INTERP, "true",4);
            false = string_from_const_cstring(INTERP, "false",5);
            yes   = string_from_const_cstring(INTERP, "yes",3);
            no    = string_from_const_cstring(INTERP, "no",2);

            fixedstringarray_typenum = pmc_type(INTERP, string_from_const_cstring(INTERP, "FixedStringArray", 0));
            string_anchor = pmc_new(INTERP,fixedstringarray_typenum);

            VTABLE_set_integer_native(INTERP,string_anchor,4);
            VTABLE_set_string_keyed_int(INTERP,string_anchor,0,true);
            VTABLE_set_string_keyed_int(INTERP,string_anchor,1,false);
            VTABLE_set_string_keyed_int(INTERP,string_anchor,2,yes);
            VTABLE_set_string_keyed_int(INTERP,string_anchor,3,no);
            dod_register_pmc(INTERP, string_anchor);
        }
    }

    INTVAL get_bool () {

        STRING* s = (STRING*) PMC_str_val(SELF);
        if (!string_compare(INTERP,s,true)) {
          return 1;
        } else if (!string_compare(INTERP,s,false)) {
          return 0;
        } else if (!string_compare(INTERP,s,yes)) {
          return 1;
        } else if (!string_compare(INTERP,s,no)) {
          return 0;
        } else if (VTABLE_get_integer(INTERP, SELF) != 0) {
          return 1;
        }

        return 0; /* XXX Throw exception about invalid boolean type. */
    }
}


/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
