linebreak 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt DELETED
@@ -1,23 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.rdoc
4
- COPYING.txt
5
- Rakefile
6
- bin/linebreak
7
- lib/aef/linebreak.rb
8
- lib/aef/linebreak/string_extension.rb
9
- lib/aef/linebreak/commands/encode.rb
10
- lib/aef/linebreak/commands/encodings.rb
11
- lib/aef/linebreak/commands/version.rb
12
- lib/aef/linebreak/pathname_conversion.rb
13
- lib/aef/linebreak/linebreak.rb
14
- spec/spec_helper.rb
15
- spec/linebreak_spec.rb
16
- spec/spec.opts
17
- spec/fixtures/unix.txt
18
- spec/fixtures/windows.txt
19
- spec/fixtures/mac.txt
20
- spec/fixtures/unix_windows.txt
21
- spec/fixtures/windows_mac.txt
22
- spec/fixtures/mac_unix.txt
23
- spec/fixtures/unix_windows_mac.txt
data/README.rdoc DELETED
@@ -1,232 +0,0 @@
1
- = Linebreak
2
-
3
- * Project: https://rubyforge.org/projects/linebreak/
4
- * RDoc: http://linebreak.rubyforge.org/
5
- * Github: http://github.com/aef/linebreak/
6
-
7
- == DESCRIPTION:
8
-
9
- Linebreak is a Ruby library and commandline tool for conversion of text
10
- between linebreak encoding formats of unix, windows or mac.
11
-
12
- == FEATURES/PROBLEMS:
13
-
14
- * Completely written in Ruby
15
- * Core class extensions are optionally loadable
16
- * Tested and fully working on:
17
- * Ubuntu Linux 9.04 i386_64
18
- * Ruby 1.8.7p72
19
- * Ruby 1.9.1p129
20
- * JRuby 1.3.1 (22 tests fail, but it's fully usable)
21
- * Debian GNU/Linux 4.0 i386
22
- * Ruby 1.8.6
23
- * Windows XP i386
24
- * Ruby 1.8.6 (tests fail completely because of problems with popen4)
25
- * The commandline tool does only work with a patched user-choices gem on Ruby
26
- 1.9 or higher. See the INSTALL section for further instructions.
27
-
28
- == SYNOPSIS:
29
-
30
- === Commandline
31
-
32
- The default output encoding is unix. You can also choose mac and windows.
33
-
34
- linebreak encode --system windows unix.txt windows.txt
35
-
36
- If no target file is specified the output will be sent to STDOUT.
37
-
38
- linebreak encode --system windows mac.txt > windows.txt
39
-
40
- You can set the default with the environment variable LINEBREAK_SYSTEM.
41
-
42
- export LINEBREAK_SYSTEM=mac
43
-
44
- linebreak encode windows.txt mac.txt
45
-
46
- If you do not specify an output file, output will be put to STDOUT. If you also
47
- do not specify an input file, input will be expected from STDIN.
48
-
49
- You can also detect the linebreak systems contained in a file in the following
50
- way:
51
-
52
- linebreak encodings windows_mac.txt
53
-
54
- If you want to ensure that a file contains the exact encodings systems you
55
- specified, you can use the following command:
56
-
57
- linebreak encodings --ensure unix,windows,mac unix.txt
58
-
59
- The results will be outputted. In case of a file containing other linebreak
60
- encoding systems there will be an exit code of 1.
61
-
62
- It is also possible to specify multiple input files or none to expect input from
63
- STDIN.
64
-
65
- === Library
66
-
67
- First of all you have to load the Linebreak gem:
68
-
69
- require 'aef/linebreak'
70
-
71
- You can put strings or objects responding to to_s into the method and
72
- optionally define a target linebreak encoding. The default encoding is :unix.
73
- You can also choose :mac and :windows. Notice that the :mac encoding is
74
- deprecated. Modern Apple machines also use :unix linebreak encoding, while
75
- Commodore machines also use the :mac linebreak encoding.
76
-
77
- windows_string = "Abcdef\r\nAbcdef\r\nAbcdef"
78
-
79
- Aef::Linebreak.encode(windows_string, :unix)
80
- #=> "Abcdef\nAbcdef\nAbcdef"
81
-
82
- You can detect which decoding systems are used in a string:
83
-
84
- mixed_unix_and_mac_string = "Abcdef\rAbcdef\nAbcdef"
85
-
86
- Aef::Linebreak.encodings(mixed_unix_and_mac_string)
87
- #=> #<Set: {:unix, :mac}>
88
-
89
- You can also easily ensure that a string contains exactly the linebreak
90
- encodings you expect it to contain:
91
-
92
- mixed_windows_and_mac_string = "Abcdef\r\nAbcdef\rAbcdef"
93
-
94
- Aef::Linebreak.encoding?(mixed_windows_and_mac_string, :windows)
95
- #=> false
96
-
97
- Aef::Linebreak.encoding?(mixed_windows_and_mac_string, :windows, :mac)
98
- #=> true
99
-
100
- Note that the expected linebreak systems could also be given as an array or a
101
- set.
102
-
103
- Alternatively you could include Linebreak into the String class and use it in
104
- the following way:
105
-
106
- require 'aef/linebreak/string_extension'
107
-
108
- "Abcdef\nAbcdef\nAbcdef".linebreak_encode(:mac)
109
- #=> "Abcdef\rAbcdef\rAbcdef"
110
-
111
- "Abcdef\r\nAbcdef\nAbcdef".linebreak_encodings
112
- #=> #<Set: {:unix, :windows}>
113
-
114
- "Abcdef\nAbcdef\nAbcdef".linebreak_encoding?(:unix, :windows)
115
- #=> false
116
-
117
- "Abcdef\nAbcdef\nAbcdef".linebreak_encoding?(:unix)
118
- #=> true
119
-
120
- == REQUIREMENTS:
121
-
122
- * rubygems
123
-
124
- === Additional for commandline
125
- * user-choices
126
-
127
- === Additional for automated testing
128
- * hoe
129
- * rspec
130
- * popen4
131
-
132
- == INSTALL:
133
-
134
- On *nix systems you may need to prefix the command with sudo to get root
135
- privileges.
136
-
137
- If you want to use the commandline tool you need to install the following gem
138
- manually:
139
-
140
- gem install user-choices
141
-
142
- On Ruby 1.9 or higher you need to install an inofficially updated version from
143
- github instead:
144
-
145
- gem install qoobaa-user-choices --source http://gems.github.com
146
-
147
- You could also patch the normal user-choices gem yourself with a patch written
148
- by me. You can find it here: https://rubyforge.org/tracker/index.php?func=detail&aid=24307&group_id=4192&atid=16176
149
-
150
- === High security (recommended)
151
-
152
- There is a high security installation option available through rubygems. It is
153
- highly recommended over the normal installation, although it may be a bit less
154
- comfortable. To use the installation method, you will need my public key, which
155
- I use for cryptographic signatures on all my gems. You can find the public key
156
- and more detailed verification information in the aef-certificates section of my
157
- rubyforge project[https://rubyforge.org/frs/?group_id=7890&release_id=31749]
158
-
159
- Add the key to your rubygems' trusted certificates by the following command:
160
-
161
- gem cert --add aef.pem
162
-
163
- Now you can install the gem while automatically verifying it's signature by the
164
- following command:
165
-
166
- gem install linebreak --ignore-dependencies -P HighSecurity
167
-
168
- Please notice that you may need other keys for dependent libraries, so you may
169
- have to install dependencies manually.
170
-
171
- === Normal (insecure)
172
-
173
- gem install linebreak
174
-
175
- === Github (also insecure)
176
-
177
- Alternatively you could install linebreak from github which may be a bit more
178
- up to date. The version may however not be as stable as the normal gem and there
179
- is no way to install the gem securely. Therefore this is not recommended.
180
-
181
- gem install aef-linebreak --source http://gems.github.com
182
-
183
- === Automated testing
184
-
185
- You can test this package through rspec on your system. First find the path
186
- where the gem was installed to:
187
-
188
- gem which aef/linebreak
189
-
190
- Go into the root directory of the installed gem and run the following command
191
- to start the test runner:
192
-
193
- rake spec
194
-
195
- If something goes wrong you should be noticed through failing examples.
196
-
197
- == DEVELOPMENT:
198
-
199
- This software is developed in the source code management system git hosted
200
- at github.com. You can download the most recent sourcecode through the following
201
- command:
202
-
203
- git clone git://github.com/aef/linebreak.git
204
-
205
- Help on making this software better is always very appreciated. If you want your
206
- changes to be included in the official release, please send me a patch through
207
- the project's tracker[https://rubyforge.org/tracker/?group_id=7890] at
208
- rubyforge.org. You can generate a patch-file by the following command:
209
-
210
- git diff > patch.diff
211
-
212
- Please make sure to write tests for your changes and notice that I can't promise
213
- to include your changes before reviewing them.
214
-
215
- == LICENSE:
216
-
217
- Copyright 2009 Alexander E. Fischer <aef@raxys.net>
218
-
219
- This file is part of Linebreak.
220
-
221
- Linebreak is free software: you can redistribute it and/or modify
222
- it under the terms of the GNU General Public License as published by
223
- the Free Software Foundation, either version 3 of the License, or
224
- (at your option) any later version.
225
-
226
- This program is distributed in the hope that it will be useful,
227
- but WITHOUT ANY WARRANTY; without even the implied warranty of
228
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
229
- GNU General Public License for more details.
230
-
231
- You should have received a copy of the GNU General Public License
232
- along with this program. If not, see <http://www.gnu.org/licenses/>.
data/bin/linebreak DELETED
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
4
- #
5
- # This file is part of Linebreak.
6
- #
7
- # Linebreak is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
-
20
- require 'rubygems'
21
- require 'aef/linebreak'
22
-
23
- # User friendly message if user-choices is not available
24
- begin
25
- require 'user-choices'
26
- rescue LoadError
27
- warn "This command needs the user-choices gem to be installed.\n\nSolution: gem install user-choices"; exit false
28
- end
29
-
30
- commands_available = {
31
- :encode => 'Convert all linebreak encodings of a file',
32
- :encodings => 'Detect linebreak encoding systems of a file',
33
- :version => 'More information about this program',
34
- :'--version' => :version,
35
- :'-v' => :version,
36
- :'-V' => :version
37
- }
38
-
39
- command_name = ARGV.shift
40
- command_name = command_name.to_sym if command_name
41
-
42
- if commands_available[command_name].nil?
43
- puts "Usage: #$PROGRAM_NAME COMMAND"
44
- puts
45
- puts 'Available commands:'
46
- puts
47
- padding = commands_available.keys.map{|symbol| symbol.to_s}.max{|a,b| a.size <=> b.size}.size
48
- commands_available.each do |command_name, description|
49
- unless description.is_a?(Symbol)
50
- printf "%-#{padding}s\t%s\n", command_name, description
51
- end
52
- end
53
- exit false
54
- else
55
- if commands_available[command_name].is_a?(Symbol)
56
- command_name = commands_available[command_name]
57
- end
58
-
59
- command = Aef::Linebreak.const_get("#{command_name.to_s.capitalize}Command").new
60
- S4tUtils.with_pleasant_exceptions {command.execute}
61
- end
@@ -1,73 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- # TODO: If user-choices patch gets accepted, use :upcase for environment variables
19
-
20
- require 'aef/linebreak/pathname_conversion'
21
-
22
- class Aef::Linebreak::EncodeCommand < UserChoices::Command
23
- include UserChoices
24
-
25
- # Prepare configuration sources
26
- def add_sources(builder)
27
- builder.add_source(
28
- CommandLineSource, :usage,
29
- "Usage: #$PROGRAM_NAME encode [OPTIONS] [INPUT] [OUTPUT]\n\n",
30
- "Convert all linebreak encodings of a file.\n",
31
- "Use the environment variable LINEBREAK_SYSTEM to specify a default output encoding.\n"
32
- )
33
-
34
- builder.add_source(EnvironmentSource, :mapping,
35
- :system => 'LINEBREAK_SYSTEM'
36
- )
37
- end
38
-
39
- # Define configuration options
40
- def add_choices(builder)
41
- systems = Aef::Linebreak::BREAK_BY_SYSTEM.keys.map{|key| key.to_s}
42
- builder.add_choice(:system, :default => 'unix', :type => systems) do |cli|
43
- cli.uses_option('-s', '--system SYSTEM',
44
- "Output encoding system. Possible settings: #{systems.join(', ')}")
45
- end
46
-
47
- builder.add_choice(:files, :length => 0..2, :type => :pathname) {|cli| cli.uses_arglist}
48
- end
49
-
50
- # Manual option post processing
51
- def postprocess_user_choices
52
- if @user_choices[:files][0] and @user_choices[:files][0] != Pathname('-')
53
- @user_choices[:input] = @user_choices[:files][0].open('r')
54
- else
55
- @user_choices[:input] = STDIN
56
- end
57
-
58
- if @user_choices[:files][1] and @user_choices[:files][1] != Pathname('-')
59
- @user_choices[:output] = @user_choices[:files][1].open('w')
60
- else
61
- @user_choices[:output] = STDOUT
62
- end
63
- end
64
-
65
- # Main program
66
- def execute
67
- @user_choices[:input].each_line do |line|
68
- @user_choices[:output] << Aef::Linebreak.encode(line, @user_choices[:system].to_sym)
69
- end
70
-
71
- [:input, :output].each {|stream| @user_choices[stream].close }
72
- end
73
- end
@@ -1,88 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak is free software: you can redistribute it and/or modify it under the
6
- # terms of the GNU General Public License as published by the Free Software
7
- # Foundation, either version 3 of the License, or (at your option) any later
8
- # version.
9
- #
10
- # This program is distributed in the hope that it will be useful, but WITHOUT
11
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
- # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13
- # details.
14
- #
15
- # You should have received a copy of the GNU General Public License along with
16
- # this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- require 'aef/linebreak/pathname_conversion'
19
-
20
- class Aef::Linebreak::EncodingsCommand < UserChoices::Command
21
- include UserChoices
22
-
23
- # Prepare configuration sources
24
- def add_sources(builder)
25
- builder.add_source(CommandLineSource, :usage,
26
- "Usage: #$PROGRAM_NAME encodings [OPTIONS] [FILE]\n\n",
27
- "Detect linebreak encoding systems of a file.\n"
28
- )
29
- end
30
-
31
- # Define configuration options
32
- def add_choices(builder)
33
- builder.add_choice(:ensure, :type => [:string]) do |cli|
34
- cli.uses_option('-e', '--ensure SYSTEMLIST',
35
- "Verify that given encodings are existent. Separated by commas without spaces. Possible settings: #{Aef::Linebreak::BREAK_BY_SYSTEM.keys.join(', ')}.")
36
- end
37
-
38
- builder.add_choice(:files, :type => :pathname) {|cli| cli.uses_arglist}
39
- end
40
-
41
- # Manual option post processing
42
- def postprocess_user_choices
43
- if @user_choices[:ensure]
44
- @user_choices[:ensure] = @user_choices[:ensure].map{|string| string.to_sym }.to_set
45
- end
46
-
47
- if @user_choices[:files].empty? or @user_choices[:files].include?(Pathname('-'))
48
- @user_choices[:files] = [STDIN]
49
- end
50
- end
51
-
52
- # Main program
53
- def execute
54
- systems_by_file = {}
55
-
56
- @user_choices[:files].each do |file|
57
- unless systems_by_file[file]
58
- systems_by_file[file] = Set.new
59
-
60
- file.each_line do |line|
61
- systems_by_file[file] = Aef::Linebreak.encodings(line) + systems_by_file[file]
62
- end
63
- end
64
- end
65
-
66
- failed = false
67
-
68
- systems_by_file.each do |file, systems|
69
- print "#{file}: " unless file == STDIN
70
-
71
- sorted_systems = systems.sort do |a,b|
72
- order = [:unix, :windows, :mac]
73
- order.index(a) <=> order.index(b)
74
- end
75
-
76
- print sorted_systems.join(',')
77
-
78
- if @user_choices[:ensure] and systems != @user_choices[:ensure]
79
- failed = true
80
- puts ' (failed)'
81
- else
82
- puts
83
- end
84
- end
85
-
86
- exit false if failed
87
- end
88
- end