linebreak 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -0
- data/COPYING.txt +674 -0
- data/History.txt +68 -0
- data/Manifest.txt +24 -0
- data/README.rdoc +232 -0
- data/Rakefile +20 -0
- data/bin/linebreak +68 -0
- data/lib/aef.rb +27 -0
- data/lib/aef/linebreak.rb +18 -0
- data/lib/aef/linebreak/commands/encode.rb +73 -0
- data/lib/aef/linebreak/commands/encodings.rb +88 -0
- data/lib/aef/linebreak/commands/version.rb +38 -0
- data/lib/aef/linebreak/linebreak.rb +122 -0
- data/lib/aef/linebreak/pathname_conversion.rb +44 -0
- data/lib/aef/linebreak/string_extension.rb +24 -0
- data/spec/fixtures/mac.txt +1 -0
- data/spec/fixtures/mac_unix.txt +2 -0
- data/spec/fixtures/unix.txt +3 -0
- data/spec/fixtures/unix_windows.txt +3 -0
- data/spec/fixtures/unix_windows_mac.txt +3 -0
- data/spec/fixtures/windows.txt +3 -0
- data/spec/fixtures/windows_mac.txt +2 -0
- data/spec/linebreak_spec.rb +380 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +138 -0
- metadata +148 -0
- metadata.gz.sig +0 -0
data/History.txt
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
=== 1.3.0 / 2009-08-11
|
2
|
+
|
3
|
+
* major enhancements
|
4
|
+
|
5
|
+
* Included methods for linebreak system detection and ensuring
|
6
|
+
* Overhauled commandline tool to support detection and ensuring
|
7
|
+
* BreakVerter renamed to Linebreak for better recognition
|
8
|
+
|
9
|
+
* minor enhancements
|
10
|
+
|
11
|
+
* String extension now loadable via require
|
12
|
+
* Most of the specifications now run on JRuby
|
13
|
+
* Used the Pathname class where possible
|
14
|
+
* Upgraded to use the latest hoe gem
|
15
|
+
|
16
|
+
=== 1.2.0 / 2009-04-05
|
17
|
+
|
18
|
+
* 2 major enhancements
|
19
|
+
|
20
|
+
* Namespaced into module Aef
|
21
|
+
* Instance method added for on demand inclusion into the String class
|
22
|
+
|
23
|
+
* 5 minor enhancements
|
24
|
+
|
25
|
+
* Better metadata for gem
|
26
|
+
* Test refactoring
|
27
|
+
* Minor refactorings
|
28
|
+
* Improved documentation
|
29
|
+
* Added test for --version command
|
30
|
+
|
31
|
+
* 1 minor bugfix
|
32
|
+
|
33
|
+
* Fixed some bugs related to Ruby 1.8.6
|
34
|
+
|
35
|
+
=== 1.1.1 / 2009-03-08
|
36
|
+
|
37
|
+
* minor enhancement
|
38
|
+
|
39
|
+
* Added a --version command to output version and licensing information
|
40
|
+
* Some test refactoring
|
41
|
+
* Some more comments
|
42
|
+
|
43
|
+
=== 1.1.0 / 2009-03-01
|
44
|
+
|
45
|
+
* 2 major enhancements
|
46
|
+
|
47
|
+
* Added automated tests for the commandline tool
|
48
|
+
* Tested compatibility with ruby 1.9.1
|
49
|
+
|
50
|
+
* 1 minor enhancement
|
51
|
+
|
52
|
+
* Added support for custom string linebreak encodings in library
|
53
|
+
|
54
|
+
=== 1.0.1 / 2009-02-24
|
55
|
+
|
56
|
+
* 1 minor enhancement
|
57
|
+
|
58
|
+
* Now tested on Windows XP
|
59
|
+
|
60
|
+
* 1 minor bugfix
|
61
|
+
|
62
|
+
* Bugfixes for commandline use
|
63
|
+
|
64
|
+
=== 1.0.0 / 2009-02-24
|
65
|
+
|
66
|
+
* 1 major enhancement
|
67
|
+
|
68
|
+
* Birthday!
|
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
+
lib/aef.rb
|
15
|
+
spec/spec_helper.rb
|
16
|
+
spec/linebreak_spec.rb
|
17
|
+
spec/spec.opts
|
18
|
+
spec/fixtures/unix.txt
|
19
|
+
spec/fixtures/windows.txt
|
20
|
+
spec/fixtures/mac.txt
|
21
|
+
spec/fixtures/unix_windows.txt
|
22
|
+
spec/fixtures/windows_mac.txt
|
23
|
+
spec/fixtures/mac_unix.txt
|
24
|
+
spec/fixtures/unix_windows_mac.txt
|
data/README.rdoc
ADDED
@@ -0,0 +1,232 @@
|
|
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 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/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.spec('linebreak') do
|
7
|
+
developer('Alexander E. Fischer', 'aef@raxys.net')
|
8
|
+
|
9
|
+
self.rubyforge_name = 'linebreak'
|
10
|
+
self.extra_dev_deps = %w{user-choices rspec popen4}
|
11
|
+
self.url = 'https://rubyforge.org/projects/aef/'
|
12
|
+
self.readme_file = 'README.rdoc'
|
13
|
+
self.extra_rdoc_files = %w{README.rdoc}
|
14
|
+
self.spec_extras = {
|
15
|
+
:rdoc_options => ['--main', 'README.rdoc', '--inline-source', '--line-numbers', '--title', 'Linebreak']
|
16
|
+
}
|
17
|
+
self.rspec_options = ['--options', 'spec/spec.opts']
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|
data/bin/linebreak
ADDED
@@ -0,0 +1,68 @@
|
|
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
|
+
|
22
|
+
# User friendly message if user-choices is not available
|
23
|
+
begin
|
24
|
+
require 'user-choices'
|
25
|
+
rescue LoadError
|
26
|
+
warn "This command needs the user-choices gem to be installed.\n\nSolution: gem install user-choices"; exit false
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'lib/aef/linebreak/pathname_conversion' rescue LoadError require 'aef/linebreak/pathname_conversion'
|
30
|
+
|
31
|
+
commands_available = {
|
32
|
+
:encode => 'Convert all linebreak encodings of a file',
|
33
|
+
:encodings => 'Detect linebreak encoding systems of a file',
|
34
|
+
:version => 'More information about this program',
|
35
|
+
:'--version' => :version,
|
36
|
+
:'-v' => :version,
|
37
|
+
:'-V' => :version
|
38
|
+
}
|
39
|
+
|
40
|
+
command_name = ARGV.shift
|
41
|
+
command_name = command_name.to_sym if command_name
|
42
|
+
|
43
|
+
if commands_available[command_name].nil?
|
44
|
+
puts "Usage: #$PROGRAM_NAME COMMAND"
|
45
|
+
puts
|
46
|
+
puts 'Available commands:'
|
47
|
+
puts
|
48
|
+
padding = commands_available.keys.map{|symbol| symbol.to_s}.max{|a,b| a.size <=> b.size}.size
|
49
|
+
commands_available.each do |command_name, description|
|
50
|
+
unless description.is_a?(Symbol)
|
51
|
+
printf "%-#{padding}s\t%s\n", command_name, description
|
52
|
+
end
|
53
|
+
end
|
54
|
+
exit false
|
55
|
+
else
|
56
|
+
if commands_available[command_name].is_a?(Symbol)
|
57
|
+
command_name = commands_available[command_name]
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
require "lib/aef/linebreak/commands/#{command_name}"
|
62
|
+
rescue LoadError
|
63
|
+
require "aef/linebreak/commands/#{command_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
command = Aef::Linebreak.const_get("#{command_name.to_s.capitalize}Command").new
|
67
|
+
S4tUtils.with_pleasant_exceptions {command.execute}
|
68
|
+
end
|
data/lib/aef.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
+
# Namespace for projects of Alexander E. Fischer <aef@raxys.net>
|
19
|
+
#
|
20
|
+
# If you want to be able to simply type Example instead of Aef::Example to
|
21
|
+
# address classes in this namespace simply write the following before using the
|
22
|
+
# classes:
|
23
|
+
#
|
24
|
+
# include Aef
|
25
|
+
module Aef
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
+
require 'lib/aef/linebreak/linebreak' rescue LoadError require 'aef/linebreak/linebreak'
|