Top Level Namespace

Defined Under Namespace

Modules: Abbreviations, ActionFileUtil, ActionInFile, ActionTextInProjectFile, ObservingContainer, ProjectFileWriter, Status Classes: Action, Array, Context, ContextFromDirectory, Contexts, GTDFileSystem, GTDFiles, GTDSystem, Inbox, InboxFromFile, Project, ProjectFromFile, UTF8Encoder

Constant Summary collapse

ENCODING_HANDLER =
UTF8Encoder.new true

Instance Method Summary collapse

Instance Method Details

#log(message, importance = 0) ⇒ Object



1
2
3
4
5
6
7
# File 'lib/logging.rb', line 1

def log(message,importance=0)
  begin
  puts Iconv.conv(GTDConfig[:console_encoding],'utf-8',message)
  rescue
    puts message + " (not decoded)"
  end
end

#os_file_name(file_name) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/encoding_handler.rb', line 7

def os_file_name(file_name)
  begin
  Iconv.conv(GTDConfig[:file_name_encoding],'utf-8',file_name)
  rescue
    puts "Shit"
  end
end

#read_and_decode(file_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/encoding_handler.rb', line 23

def read_and_decode(file_name)
  fn = file_name
  os_encoded_file_name = os_file_name(file_name)
  file = File.new(os_encoded_file_name,'r')
  cd = CharDet.detect(file.read) 
  #log "File #{file_name}: Encoding #{cd['encoding']} with probability #{cd['confidence']}"
  iso = Iconv.new('utf-8',cd['encoding'] )
  file.rewind
  #log "File #{file_name} encoded in #{"
  if cd['encoding'] == "UTF-8" then file.seek(3) end
  begin
    return iso.iconv(file.read)
  rescue Iconv::IllegalSequence
    log "Bad encoding in #{file_name}"
  end

end

#utf_file_name(file_name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/encoding_handler.rb', line 15

def utf_file_name(file_name)
  begin
  Iconv.conv('utf-8',GTDConfig[:file_name_encoding],file_name)
  rescue
    puts "Shit"
  end
end

#write_to_encoded_file(file_name, text) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/encoding_handler.rb', line 41

def write_to_encoded_file(file_name,text)
  File.open(os_file_name(file_name),"w") do |file|
   file.puts ENCODING_HANDLER.encode(text)
  end 
    
  #log "To #{file_name} writing #{ENCODING_HANDLER.encode(text)}"    
end