Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

removing stree string

  • Loading branch information...
commit caaf350872a4599643966adcde50371866a25cf5 1 parent cd3e395
Aaron Patterson authored
1  ext/stree/stree.c
@@ -51,6 +51,5 @@ void Init_stree()
51 51 rb_define_method(cStree, "push", push, 1);
52 52 rb_define_method(cStree, "longest_common_substr", longest_common_substr, 2);
53 53
54   - Init_stree_string();
55 54 Init_stree_stringset();
56 55 }
1  ext/stree/stree.h
@@ -6,7 +6,6 @@
6 6 #include <stree/lst_stree.h>
7 7 #include <stree/lst_algorithms.h>
8 8
9   -#include <stree_string.h>
10 9 #include <stree_stringset.h>
11 10
12 11 extern VALUE cStree;
67 ext/stree/stree_string.c
... ... @@ -1,67 +0,0 @@
1   -#include <stree_string.h>
2   -
3   -VALUE cStreeString;
4   -
5   -static void dealloc(void * ptr)
6   -{
7   - lst_string_free((LST_String *)ptr);
8   -}
9   -
10   -static VALUE allocate(VALUE klass)
11   -{
12   - LST_String * ptr;
13   - return Data_Make_Struct(klass, LST_String, NULL, dealloc, ptr);
14   -}
15   -
16   -static VALUE initialize(VALUE self, VALUE string)
17   -{
18   - LST_String * ptr;
19   -
20   - Data_Get_Struct(self, LST_String, ptr);
21   - lst_string_init(ptr, StringValuePtr(string), sizeof(char), RSTRING_LEN(string));
22   -
23   - return self;
24   -}
25   -
26   -static VALUE bytesize(VALUE self)
27   -{
28   - LST_String * ptr;
29   -
30   - Data_Get_Struct(self, LST_String, ptr);
31   - return INT2NUM(lst_string_get_length(ptr));
32   -}
33   -
34   -static VALUE get(VALUE self, VALUE index)
35   -{
36   - LST_String * ptr;
37   -
38   - Data_Get_Struct(self, LST_String, ptr);
39   -
40   - void * item = lst_string_get_item(ptr, NUM2INT(index));
41   -
42   - if(NULL == item) return Qnil;
43   -
44   - char * c = ((char *)item)[0];
45   -
46   - if(c) return INT2NUM(((char *)item)[0]);
47   - return Qnil;
48   -}
49   -
50   -static VALUE to_s(VALUE self)
51   -{
52   - LST_String * ptr;
53   -
54   - Data_Get_Struct(self, LST_String, ptr);
55   - return rb_str_new2(lst_string_print(ptr));
56   -}
57   -
58   -void Init_stree_string()
59   -{
60   - cStreeString = rb_define_class_under(cStree, "String", rb_cObject);
61   - rb_define_alloc_func(cStreeString, allocate);
62   -
63   - rb_define_method(cStreeString, "initialize", initialize, 1);
64   - rb_define_method(cStreeString, "bytesize", bytesize, 0);
65   - rb_define_method(cStreeString, "[]", get, 1);
66   - rb_define_method(cStreeString, "to_s", to_s, 0);
67   -}
10 ext/stree/stree_string.h
... ... @@ -1,10 +0,0 @@
1   -#ifndef RUBY_STREE_STRING
2   -#define RUBY_STREE_STRING
3   -
4   -#include <stree.h>
5   -
6   -void Init_stree_string();
7   -
8   -extern VALUE cStreeString;
9   -
10   -#endif
29 test/test_string.rb
... ... @@ -1,29 +0,0 @@
1   -require "test/unit"
2   -require "stree"
3   -
4   -class Stree
5   - class TestString < Test::Unit::TestCase
6   - def test_bytesize
7   - str = "foo"
8   - assert_equal str.bytesize, Stree::String.new(str).bytesize
9   - end
10   -
11   - def test_square
12   - str = "foo"
13   - sstr = Stree::String.new(str)
14   -
15   - 0.upto(str.bytesize) do |i|
16   - if str.respond_to?(:getbyte)
17   - assert_equal str.getbyte(i), sstr[i], "failed on #{i}"
18   - else
19   - assert_equal str[i], sstr[i], "failed on #{i}"
20   - end
21   - end
22   - end
23   -
24   - def test_to_s
25   - sstr = Stree::String.new("foo")
26   - assert_equal 'foo', sstr.to_s
27   - end
28   - end
29   -end

0 comments on commit caaf350

Please sign in to comment.
Something went wrong with that request. Please try again.