pcut 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+
2
+ === 0.1.0 2012-03-29
3
+
4
+ * Add 2 features:
5
+ * -c to skip continuous delimiters
6
+ * -j to specifies char to join cut result
7
+
8
+ === 0.0.2 2012-03-29
9
+
1
10
  === 0.0.1 2012-03-29
2
11
 
3
12
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -1,4 +1,3 @@
1
- .README.rdoc.swp
2
1
  History.txt
3
2
  Manifest.txt
4
3
  PostInstall.txt
data/README.rdoc CHANGED
@@ -64,9 +64,25 @@ You can set multiple chars to quote.
64
64
 
65
65
  === sub queries
66
66
 
67
-
68
-
69
-
67
+ You can get partial string by cutting the cut result again
68
+ with original syntax [/#{delimiter}/, #{index}].
69
+ This is useful for getting platform from UserAgent, or getting file extention
70
+ string from PATH.
71
+
72
+ $ cat test | pcut -d " " --preview --vertical -q "D[" -k -f "4, 5"
73
+ [4][10/Oct/2000:13:55:36 -0700]
74
+ [5]"GET /apache_pb.gif HTTP/1.0"
75
+
76
+ $ cat test | pcut -d " " --preview --vertical -q "D[" -k -f "4, 5.[/ /,2]"
77
+ [4][10/Oct/2000:13:55:36 -0700]
78
+ [5.[/ /,2]]/apache_pb.gif
79
+
80
+ $ cat test | pcut -d " " --preview --vertical -q "D[" -k -f "4, 5.[/ /,2].[/./,2]"
81
+ [4][10/Oct/2000:13:55:36 -0700]
82
+ [5.[/ /,2].[/./,2]]gif
83
+
84
+ $ cat test | pcut -d " " -q "D[" -k -f "4, 5.[/ /,2].[/./,2]"
85
+ [10/Oct/2000:13:55:36 -0700] gif
70
86
 
71
87
  == SYNOPSIS:
72
88
 
data/bin/pcut CHANGED
@@ -50,6 +50,15 @@ end
50
50
  opt.on('-n', '--no-color', 'turn colot output off') do
51
51
  cli.color = false
52
52
  end
53
+ opt.on('-c', '--skip-continuous-deimiters',
54
+ 'treat continuous delimiters as one delimiter') do
55
+ cli.skip_continuous_delimiters = true
56
+ end
57
+ opt.on('-j JOIN', '--join JOIN',
58
+ 'JOIN specifies the letter used to join cut result.',
59
+ 'You can use "TAB" to specify tab character.') do |v|
60
+ cli.set_joiner(v)
61
+ end
53
62
 
54
63
  begin
55
64
  opt.parse!(ARGV)
data/lib/pcut.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Pcut
5
- VERSION = '0.0.2'
5
+ VERSION = '0.1.0'
6
6
  end
data/lib/pcut/cli.rb CHANGED
@@ -19,7 +19,8 @@ module Pcut
19
19
  :keep_quote,
20
20
  :preview,
21
21
  :vertical,
22
- :color
22
+ :color,
23
+ :skip_continuous_delimiters
23
24
 
24
25
  def initialize
25
26
  @delimiter = "\t"
@@ -30,6 +31,19 @@ module Pcut
30
31
  @preview = false
31
32
  @vertical = false
32
33
  @color = true
34
+ @skip_continuous_delimiters = false
35
+ end
36
+
37
+ def set_joiner(char)
38
+ if char == "TAB"
39
+ @joiner = "\t"
40
+ return
41
+ end
42
+ if char.size != 1
43
+ STDERR.puts "join char must be 1 byte char or 'TAB'"
44
+ exit(1)
45
+ end
46
+ @joiner = char
33
47
  end
34
48
 
35
49
  def parse_field(str)
@@ -74,6 +88,7 @@ module Pcut
74
88
  begin
75
89
  parser = Pcut::LineParser.new
76
90
  parser.set_delimiter(@delimiter)
91
+ parser.skip_continuous_delimiters = @skip_continuous_delimiters
77
92
  @quote.each_char { |c| parser.set_quote_guard(c) } if @quote
78
93
  parser.keep_quotes = true if @keep_quote
79
94
  rescue => e
@@ -17,13 +17,18 @@ module Pcut
17
17
  }
18
18
  DELIMITER = "\t"
19
19
 
20
- attr_reader :quote_guard
21
- attr_accessor :keep_quotes
20
+ attr_accessor \
21
+ :quote_guard,
22
+ :keep_quotes,
23
+ :skip_continuous_delimiters
22
24
 
23
25
  def initialize
24
26
  @quote_guard = {}
25
27
  @delimiter = DELIMITER
26
- @keep_quotes = false # do not delete quoting chars
28
+ # do not delete quoting chars
29
+ @keep_quotes = false
30
+ # treat continuous delimiters as one delimiters
31
+ @skip_continuous_delimiters = false
27
32
  end
28
33
 
29
34
  def set_quote_guard(quote)
@@ -49,6 +54,13 @@ module Pcut
49
54
 
50
55
  str.each_char do |c|
51
56
 
57
+ # skip continuous delimiters
58
+ if skip_continuous_delimiters &&
59
+ @delimiter == c &&
60
+ @delimiter == previous_char
61
+ next
62
+ end
63
+
52
64
  # check starting quote
53
65
  if @quote_guard.include?(c) &&
54
66
  previous_char != "\\" # not escaped
@@ -182,6 +182,13 @@ describe Pcut::LineParser do
182
182
 
183
183
  end
184
184
 
185
+ it 'skips continuous delimiters if needed' do
186
+ @parser.skip_continuous_delimiters = true
187
+ @parser.set_delimiter(" ")
188
+ result = @parser.parse("1979 8 23 bonar ")
189
+ result.should == ['1979', '8', '23', 'bonar']
190
+ end
191
+
185
192
  describe 'real world sample' do
186
193
 
187
194
  before(:each) do
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nakano Kyohei (bonar)
@@ -94,7 +94,6 @@ extra_rdoc_files:
94
94
  - PostInstall.txt
95
95
  - README.rdoc
96
96
  files:
97
- - .README.rdoc.swp
98
97
  - History.txt
99
98
  - Manifest.txt
100
99
  - PostInstall.txt
data/.README.rdoc.swp DELETED
Binary file