cvsuser     01/11/12 20:35:46

  Modified:    docs     strings.pod
               include/parrot exceptions.h string.h
               t/op     string.t
  Log:
  core.ops - Added ord operator, documentation
  string.c - Added string_ord, _string_index (_string_index is a static helper)        
      Patched string_concat to handle null strings properly.
  docs/strings.pod - Description of string_ord
  include/parrot/exceptions.h - Added ORD_OUT_OF_STRING exception
  include/parrot/string.h - Added string_ord()
  t/op/string.t - Added full set of test for ord_i_(s|sc)(_(i|ic))?
  
  string.c contains a bit of documentation explaining the logic behind
  _string_index, primarily having to do with multiple encoding formats.
  
  Revision  Changes    Path
  1.6       +13 -0     parrot/docs/strings.pod
  
  Index: strings.pod
  ===================================================================
  RCS file: /cvs/public/parrot/docs/strings.pod,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- strings.pod       2001/10/10 18:21:04     1.5
  +++ strings.pod       2001/11/13 04:35:46     1.6
  @@ -89,6 +89,19 @@
   C<*dest> is a null pointer, a new string structure is created with the
   same encoding as C<src>.)
   
  +To retrieve a single character of the string, call
  +
  +    INTVAL string_ord(STRING* s, INTVAL n)
  +
  +The result will be returned from the function. It checks for the existence of
  +C<s>, and tests for C<n> being out of range. Currently it applies the method
  +that perl uses on arrays to handle negative indices. That is to say, negative
  +values count backwards from the end of the string. For example, index -1 is
  +the last character in the string, -2 is the next-to-last, and so on.
  +
  +If C<s> is null or C<s> is zero-length, it throws an exception. If C<n> is out
  +of range, it also throws an exception.
  +
   To compare two strings, use:
   
       INTVAL string_compare(STRING* s1, STRING* s2)
  
  
  
  1.5       +2 -1      parrot/include/parrot/exceptions.h
  
  Index: exceptions.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/exceptions.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- exceptions.h      2001/10/31 22:51:32     1.4
  +++ exceptions.h      2001/11/13 04:35:46     1.5
  @@ -1,7 +1,7 @@
   /* exceptions.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: exceptions.h,v 1.4 2001/10/31 22:51:32 tom Exp $
  + *     $Id: exceptions.h,v 1.5 2001/11/13 04:35:46 jgoff Exp $
    *  Overview:
    *     define the internal interpreter exceptions
    *  Data Structure and Algorithms:
  @@ -17,6 +17,7 @@
   
   #define NO_REG_FRAMES 1
   #define SUBSTR_OUT_OF_STRING 1
  +#define ORD_OUT_OF_STRING 1
   #define MALFORMED_UTF8 1
   #define MALFORMED_UTF16 1
   #define MALFORMED_UTF32 1
  
  
  
  1.10      +3 -1      parrot/include/parrot/string.h
  
  Index: string.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/string.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- string.h  2001/10/31 22:51:32     1.9
  +++ string.h  2001/11/13 04:35:46     1.10
  @@ -1,7 +1,7 @@
   /* string.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: string.h,v 1.9 2001/10/31 22:51:32 tom Exp $
  + *     $Id: string.h,v 1.10 2001/11/13 04:35:46 jgoff Exp $
    *  Overview:
    *     This is the api header for the string subsystem
    *  Data Structure and Algorithms:
  @@ -45,6 +45,8 @@
   /* Declarations of other functions */
   INTVAL
   string_length(STRING*);
  +INTVAL
  +string_ord(STRING* s, INTVAL index);
   void
   string_grow(STRING* s, INTVAL newsize);
   void
  
  
  
  1.13      +125 -1    parrot/t/op/string.t
  
  Index: string.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/op/string.t,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- string.t  2001/10/16 18:35:04     1.12
  +++ string.t  2001/11/13 04:35:46     1.13
  @@ -1,6 +1,6 @@
   #! perl -w
   
  -use Parrot::Test tests => 24;
  +use Parrot::Test tests => 43;
   
   output_is( <<'CODE', <<OUTPUT, "set_s_sc" );
        set     S4, "JAPH\n"
  @@ -127,7 +127,30 @@
   length 21
   OUTPUT
   
  +output_is( <<'CODE', '', "2-param concat, null onto null" );
  +    concat S0,S0
  +    end
  +CODE
  +
  +output_is( <<'CODE', <<OUTPUT, '2-param concat, "foo1" onto null' );
  +    concat S0,"foo1"
  +    print S0
  +    print "\n"
  +    end
  +CODE
  +foo1
  +OUTPUT
   
  +output_is( <<'CODE', <<OUTPUT, '2-param concat, "foo2" onto null' );
  +    set S1,"foo2"
  +    concat S0,S1
  +    print S0
  +    print "\n"
  +    end
  +CODE
  +foo2
  +OUTPUT
  +
   output_is( <<'CODE', <<OUTPUT, "concat" );
       set S1, "fish"
       set S2, "bone"
  @@ -140,6 +163,7 @@
   fishbone
   OUTPUT
   
  +
   output_is(<<"CODE", <<'OUTPUT', "clears");
   @{[ set_str_regs( sub {"BOO $_[0]\\n"} ) ]}
        clears
  @@ -309,7 +333,107 @@
   foo
   OUTPUT
   
  +output_is(<<'CODE','Cannot get character of empty string','2-param ord, empty 
string');
  +     ord I0,""
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE','Cannot get character of empty string','2-param ord, empty 
string register');
  +     ord I0,S0
  +     print I0
  +     end
  +CODE
   
  +output_is(<<'CODE','Cannot get character of empty string','3-param ord, empty 
string');
  +     ord I0,"",0
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE','Cannot get character of empty string','3-param ord, empty 
string register');
  +     ord I0,S0,0
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'2-param ord, one-character string');
  +     ord I0,"a"
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'2-param ord, one-character string register');
  +     set S0,"a"
  +     ord I0,S0
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'3-param ord, one-character string');
  +     ord I0,"a",0
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'3-param ord, one-character string register');
  +     set S0,"a"
  +     ord I0,S0,0
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('b'),'3-param ord, multi-character string');
  +     ord I0,"ab",1
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('b'),'3-param ord, multi-character string register');
  +     set S0,"ab"
  +     ord I0,S0,1
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE', 'Cannot get character past end of string','3-param ord, 
multi-character string');
  +     ord I0,"ab",2
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE', 'Cannot get character past end of string','3-param ord, 
multi-character string');
  +     set S0,"ab"
  +     ord I0,S0,2
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'3-param ord, one-character string, from end');
  +     ord I0,"a",-1
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('a'),'3-param ord, one-character string register, from end');
  +     set S0,"a"
  +     ord I0,S0,-1
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('b'),'3-param ord, multi-character string, from end');
  +     ord I0,"ab",-1
  +     print I0
  +     end
  +CODE
  +
  +output_is(<<'CODE',ord('b'),'3-param ord, multi-character string register, from 
end');
  +     set S0,"ab"
  +     ord I0,S0,-1
  +     print I0
  +     end
  +CODE
   
   # Set all string registers to values given by &$_[0](reg num)
   sub set_str_regs {
  
  
  


Reply via email to