console 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/console/console.c +4 -4
  2. data/test/console.rb +39 -39
  3. metadata +5 -5
@@ -63,7 +63,7 @@ static const char* default_pad_string = " ";
63
63
 
64
64
  /*
65
65
  * call-seq:
66
- * slice(string, start_offset, display_width=1, pad_string=" ")
66
+ * display_slice(string, start_offset, display_width=1, pad_string=" ")
67
67
  *
68
68
  * Returns a slice of a string based on display width, rather than character or
69
69
  * bytes. I.e, the <code>start_offset</code> and <code>display_width</code>
@@ -89,7 +89,7 @@ static const char* default_pad_string = " ";
89
89
  * The returned string WILL be in the current locale encoding, regardless of the
90
90
  * encoding of the original string.
91
91
  */
92
- static VALUE slice(int argc, VALUE *argv, VALUE v_self) {
92
+ static VALUE display_slice(int argc, VALUE *argv, VALUE v_self) {
93
93
  VALUE v_string, v_display_start, v_display_width, v_pad_string;
94
94
  rb_scan_args(argc, argv, "22", &v_string, &v_display_start, &v_display_width, &v_pad_string);
95
95
  Check_Type(v_string, T_STRING);
@@ -189,7 +189,7 @@ static VALUE slice(int argc, VALUE *argv, VALUE v_self) {
189
189
  *
190
190
  * Console.display_width: get the number of display columns used by a string.
191
191
  *
192
- * Console.slice: get a substrig by display column offset and size.
192
+ * Console.display_slice: get a substrig by display column offset and size.
193
193
  *
194
194
  */
195
195
 
@@ -198,6 +198,6 @@ void Init_console() {
198
198
 
199
199
  cConsole = rb_define_class("Console", rb_cObject);
200
200
  rb_define_module_function(cConsole, "display_width", display_width, 1);
201
- rb_define_module_function(cConsole, "slice", slice, -1);
201
+ rb_define_module_function(cConsole, "display_slice", display_slice, -1);
202
202
  }
203
203
 
@@ -14,76 +14,76 @@ class ConsoleTest < ::Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_slice_of_zero_width_is_empty_string
17
- assert_equal "", Console.slice(@s, 0, 0)
18
- assert_equal "", Console.slice(@s, 1, 0)
17
+ assert_equal "", Console.display_slice(@s, 0, 0)
18
+ assert_equal "", Console.display_slice(@s, 1, 0)
19
19
  end
20
20
 
21
21
  def test_slice_out_of_bounds_is_nil
22
- assert_equal nil, Console.slice(@s, 100, 3)
23
- assert_equal nil, Console.slice(@s, -100, 3)
22
+ assert_equal nil, Console.display_slice(@s, 100, 3)
23
+ assert_equal nil, Console.display_slice(@s, -100, 3)
24
24
  end
25
25
 
26
26
  def test_slice_with_negative_offset
27
- assert_equal "ê", Console.slice(@s, -1, 1)
28
- assert_equal "aê", Console.slice(@s, -2, 2)
29
- assert_equal "a", Console.slice(@s, -2, 1)
27
+ assert_equal "ê", Console.display_slice(@s, -1, 1)
28
+ assert_equal "aê", Console.display_slice(@s, -2, 2)
29
+ assert_equal "a", Console.display_slice(@s, -2, 1)
30
30
  end
31
31
 
32
32
  def test_slice_width_argument_defaults_to_1
33
- assert_equal "ê", Console.slice(@s, -1)
34
- assert_equal "a", Console.slice(@s, -2)
33
+ assert_equal "ê", Console.display_slice(@s, -1)
34
+ assert_equal "a", Console.display_slice(@s, -2)
35
35
  end
36
36
 
37
37
  def test_slice_works_on_chinese_characters
38
- assert_equal "能", Console.slice(@s, 0, 2);
39
- assert_equal "能吞", Console.slice(@s, 0, 4);
40
- assert_equal "能吞a", Console.slice(@s, 0, 5);
41
- assert_equal "能吞aê", Console.slice(@s, 0, 6);
38
+ assert_equal "能", Console.display_slice(@s, 0, 2);
39
+ assert_equal "能吞", Console.display_slice(@s, 0, 4);
40
+ assert_equal "能吞a", Console.display_slice(@s, 0, 5);
41
+ assert_equal "能吞aê", Console.display_slice(@s, 0, 6);
42
42
  end
43
43
 
44
44
  def test_slice_with_excessive_width_is_still_cool
45
- assert_equal "能吞aê", Console.slice(@s, 0, 100);
46
- assert_equal "吞aê", Console.slice(@s, 2, 100);
47
- assert_equal "aê", Console.slice(@s, 4, 100);
48
- assert_equal "ê", Console.slice(@s, 5, 100);
49
- assert_equal "", Console.slice(@s, 6, 100); # yep, we get a non-nil at this value
50
- assert_equal nil, Console.slice(@s, 7, 100);
45
+ assert_equal "能吞aê", Console.display_slice(@s, 0, 100);
46
+ assert_equal "吞aê", Console.display_slice(@s, 2, 100);
47
+ assert_equal "aê", Console.display_slice(@s, 4, 100);
48
+ assert_equal "ê", Console.display_slice(@s, 5, 100);
49
+ assert_equal "", Console.display_slice(@s, 6, 100); # yep, we get a non-nil at this value
50
+ assert_equal nil, Console.display_slice(@s, 7, 100);
51
51
  end
52
52
 
53
53
  def test_slice_with_the_biggest_valid_start_offset_behaves_like_String_slice_does
54
- assert_equal "", Console.slice(@s, 6, 100);
55
- assert_equal "", Console.slice(@s, 6, 0);
56
- assert_equal nil, Console.slice(@s, 6, -1);
54
+ assert_equal "", Console.display_slice(@s, 6, 100);
55
+ assert_equal "", Console.display_slice(@s, 6, 0);
56
+ assert_equal nil, Console.display_slice(@s, 6, -1);
57
57
  end
58
58
 
59
59
  def test_slice_misaligned_start_offsets_get_padded
60
60
  s = "能吞aê"
61
61
 
62
- assert_equal "", Console.slice(@s, 0, 0)
63
- assert_equal " ", Console.slice(@s, 0, 1)
64
- assert_equal "能", Console.slice(@s, 0, 2)
65
- assert_equal "能 ", Console.slice(@s, 0, 3)
62
+ assert_equal "", Console.display_slice(@s, 0, 0)
63
+ assert_equal " ", Console.display_slice(@s, 0, 1)
64
+ assert_equal "能", Console.display_slice(@s, 0, 2)
65
+ assert_equal "能 ", Console.display_slice(@s, 0, 3)
66
66
 
67
- assert_equal "", Console.slice(@s, 1, 0)
68
- assert_equal " ", Console.slice(@s, 1, 1)
69
- assert_equal " ", Console.slice(@s, 1, 2)
70
- assert_equal " 吞", Console.slice(@s, 1, 3)
67
+ assert_equal "", Console.display_slice(@s, 1, 0)
68
+ assert_equal " ", Console.display_slice(@s, 1, 1)
69
+ assert_equal " ", Console.display_slice(@s, 1, 2)
70
+ assert_equal " 吞", Console.display_slice(@s, 1, 3)
71
71
 
72
- assert_equal "", Console.slice(@s, 3, 0);
73
- assert_equal " ", Console.slice(@s, 3, 1);
74
- assert_equal " a", Console.slice(@s, 3, 2);
75
- assert_equal " aê", Console.slice(@s, 3, 3);
72
+ assert_equal "", Console.display_slice(@s, 3, 0);
73
+ assert_equal " ", Console.display_slice(@s, 3, 1);
74
+ assert_equal " a", Console.display_slice(@s, 3, 2);
75
+ assert_equal " aê", Console.display_slice(@s, 3, 3);
76
76
  end
77
77
 
78
78
  def test_slice_misaligned_start_offsets_get_padded_with_specified_character
79
- assert_equal "", Console.slice(@s, 0, 0, "X")
80
- assert_equal "X", Console.slice(@s, 0, 1, "X")
81
- assert_equal "XX", Console.slice(@s, 1, 2, "X")
79
+ assert_equal "", Console.display_slice(@s, 0, 0, "X")
80
+ assert_equal "X", Console.display_slice(@s, 0, 1, "X")
81
+ assert_equal "XX", Console.display_slice(@s, 1, 2, "X")
82
82
  end
83
83
 
84
84
  def test_slice_fails_on_nonstrings
85
- assert_raises(TypeError) { Console.slice :potato, 1, 1 }
86
- assert_raises(TypeError) { Console.slice 3, 1, 1 }
85
+ assert_raises(TypeError) { Console.display_slice :potato, 1, 1 }
86
+ assert_raises(TypeError) { Console.display_slice 3, 1, 1 }
87
87
  end
88
88
 
89
89
  def test_display_width_empty_string_is_zero
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- version: "0.1"
7
+ - 2
8
+ version: "0.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - William Morgan
@@ -13,11 +13,11 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-05-10 21:59:22 -04:00
16
+ date: 2010-05-11 08:47:32 -04:00
17
17
  default_executable:
18
18
  dependencies: []
19
19
 
20
- description: Console is a hlper for displaying super-ASCII strings on the console. It turns out that all these funny foreign characters not only take up strange numbers of bytes, they also take up strange numbers of columns on the screen when you print them. Console procides utility methods for determining the display width of a string, and for taking a substring in a display-width-centric manner.
20
+ description: Console is a helper class for displaying super-ASCII strings on the console. Console is needed when you want to mix two-column (e.g. Chinese) and single-column (e.g. ASCII) characters and know how much horizontal realestate the result takes on the screen. This is generally necessary when you want to have internationalization support in a console program. Console currently provides utility methods for determining the display width of a string, and for taking a substring based on display position and display width.
21
21
  email: wmorgan-console@masanjin.net
22
22
  executables: []
23
23
 
@@ -30,7 +30,7 @@ files:
30
30
  - ext/console/console.c
31
31
  - test/console.rb
32
32
  has_rdoc: true
33
- homepage: http://console.rubyforge.org
33
+ homepage: http://console.rubygems.org
34
34
  licenses: []
35
35
 
36
36
  post_install_message: