Package translate :: Package storage :: Module symbian |
[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.symbian

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  #
     4  # Copyright 2008 Zuza Software Foundation
     5  #
     6  # This file is part of translate.
     7  #
     8  # translate is free software; you can redistribute it and/or modify
     9  # it under the terms of the GNU General Public License as published by
    10  # the Free Software Foundation; either version 2 of the License, or
    11  # (at your option) any later version.
    12  #
    13  # translate is distributed in the hope that it will be useful,
    14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  # GNU General Public License for more details.
    17  #
    18  # You should have received a copy of the GNU General Public License
    19  # along with translate; if not, write to the Free Software
    20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    21
    22  import re
    23
    24  charset_re = re.compile('CHARACTER_SET[ ]+(?P<charset>.*)')
    25  header_item_or_end_re = re.compile('(((?P<key>[^ ]+)(?P<space>[ ]*:[ ]*)(?P<value>.*))|(?P<end_comment>[*]/))')
    26  header_item_re = re.compile('(?P<key>[^ ]+)(?P<space>[ ]*:[ ]*)(?P<value>.*)')
    27  string_entry_re = re.compile('(?P<start>rls_string[ ]+)(?P<id>[^ ]+)(?P<space>[ ]+)(?P<str>.*)')
    28
    29 -def identity(x):
    30      return x
    31
    32 -class ParseState(object):
    33 -    def __init__(self, f, charset, read_hook=identity):
    34          self.f = f
    35          self.charset = charset
    36          self.current_line = u''
    37          self.read_hook = read_hook
    38          self.read_line()
    39
    40 -    def read_line(self):
    41          current_line = self.current_line
    42          self.read_hook(current_line)
    43          self.current_line = self.f.next().decode(self.charset)
    44          return current_line
    45
    46 -def read_while(ps, f, test):
    47      result = f(ps.current_line)
    48      while test(result):
    49          ps.read_line()
    50          result = f(ps.current_line)
    51      return result
    52
    53 -def eat_whitespace(ps):
    54      read_while(ps, identity, lambda line: line.strip() == '')
    55
    56 -def skip_no_translate(ps):
    57      if ps.current_line.startswith('// DO NOT TRANSLATE'):
    58          ps.read_line()
    59          read_while(ps, identity, lambda line: not line.startswith('// DO NOT TRANSLATE'))
    60          ps.read_line()
    61          eat_whitespace(ps)
    62
    63 -def read_charset(lines):
    64      for line in lines:
    65          match = charset_re.match(line)
    66          if match is not None:
    67              return match.groupdict()['charset']
    68      return 'UTF-8'
    69