def posix_to_ldml(fmt, locale):
 buf = []
 pc = False
 quoted = []
 for c in fmt:
  if ((not pc) and c.isalpha()):
   quoted.append((c if (c != "'") else "''"))
   continue
  if quoted:
   buf.append("'")
   buf.append(''.join(quoted))
   buf.append("'")
   quoted = []
  if pc:
   if (c == '%'):
    buf.append('%')
   elif (c == 'x'):
    buf.append(locale.date_formats['short'].pattern)
   elif (c == 'X'):
    buf.append(locale.time_formats['medium'].pattern)
   else:
    buf.append(POSIX_TO_LDML[c])
   pc = False
  elif (c == '%'):
   pc = True
  else:
   buf.append(c)
 if quoted:
  buf.append("'")
  buf.append(''.join(quoted))
  buf.append("'")
 return ''.join(buf)

def posix_to_ldml ( fmt , locale ) : buf = [ ] pc = False quoted = [ ] for c in fmt : if ( ( not pc ) and c . isalpha ( ) ) : quoted . append ( ( c if ( c != "'" ) else "''" ) ) continue if quoted : buf . append ( "'" ) buf . append ( '' . join ( quoted ) ) buf . append ( "'" ) quoted = [ ] if pc : if ( c == '%' ) : buf . append ( '%' ) elif ( c == 'x' ) : buf . append ( locale . date_formats [ 'short' ] . pattern ) elif ( c == 'X' ) : buf . append ( locale . time_formats [ 'medium' ] . pattern ) else : buf . append ( POSIX_TO_LDML [ c ] ) pc = False elif ( c == '%' ) : pc = True else : buf . append ( c ) if quoted : buf . append ( "'" ) buf . append ( '' . join ( quoted ) ) buf . append ( "'" ) return '' . join ( buf )
converts a posix/strftime pattern into an ldml date format pattern .