Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/textutils/core_ext/file.rb
Class Method Summary collapse
Class Method Details
.read_utf8(path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/textutils/core_ext/file.rb', line 4 def self.read_utf8( path ) text = open( path, 'r:bom|utf-8' ) do |file| file.read end ## ## todo: make normalize newlines into a filter (for easy (re)use) ## normalize newlines ## always use LF \n (Unix): ## ## convert CR/LF \r\n (Windows) => \n ## convert CR \r (old? Mac) => \n -- still in use? text = text.gsub( /\r\n|\r/, "\n" ) # NB: for convenience: convert fancy unicode dashes/hyphens to plain ascii hyphen-minus text = TextUtils.convert_unicode_dashes_to_plain_ascii( text, path: path ) text end |