/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/VcardImporter.java

  • Committer: edam
  • Date: 2012-12-20 17:32:37 UTC
  • Revision ID: tim@ed.am-20121220173237-gmimhhsosiahq9po
be less sensitive to case when parsing vCard params

Show diffs side-by-side

added added

removed removed

681
681
                                        parseADR( name_param_parts, complete_value );
682
682
                                else if( name_param_parts[ 0 ].equals( "LABEL" ) )
683
683
                                        parseLABEL( name_param_parts, complete_value );
 
684
                                else if( name_param_parts[ 0 ].equals( "NOTE" ) )
 
685
                                        parseNOTE( name_param_parts, complete_value );
684
686
                        }
685
687
                }
686
688
 
758
760
                                in_escape = false;
759
761
                                switch( c )
760
762
                                {
 
763
                                case 'T':
 
764
                                case 't':
 
765
                                        // add tab (invalid/non-standard, but accepted)
 
766
                                        ret.append( '\t' );
 
767
                                        break;
761
768
                                case 'N':
762
769
                                case 'n':
763
770
                                        // add newline
771
778
                                        break;
772
779
                                default:
773
780
                                        // unknown escape sequence, so add it unescaped
 
781
                                        // (invalid/non-standard, but accepted)
774
782
                                        ret.append( "\\" );
775
783
                                        ret.append( Character.toChars( c ) );
776
784
                                        break;
965
973
                        addAddress( unescapeValue( value ), type );
966
974
                }
967
975
 
 
976
                private void parseNOTE( String[] params, String value )
 
977
                {
 
978
                        addNote( unescapeValue( value ) );
 
979
                }
 
980
 
968
981
                public void finaliseVcard()
969
982
                        throws ParseException, ContactNotIdentifiableException
970
983
                {
1000
1013
                        HashSet< String > ret = new HashSet< String >();
1001
1014
 
1002
1015
                        Pattern p = Pattern.compile(
1003
 
                                "^" + name + "[ \\t]*=[ \\t]*(\"?)(.*)\\1$" );
 
1016
                                "^" + name + "[ \\t]*=[ \\t]*(\"?)(.*)\\1$",
 
1017
                                Pattern.CASE_INSENSITIVE );
1004
1018
                        for( int i = 0; i < params.length; i++ ) {
1005
1019
                                Matcher m = p.matcher( params[ i ] );
1006
1020
                                if( m.matches() )
1014
1028
                 * Amongst the params, return any type values present. For v2.1 vCards,
1015
1029
                 * those types are just parameters. For v3.0, they are prefixed with
1016
1030
                 * "TYPE=". There may also be multiple type parameters.
1017
 
                 * @param params
1018
 
                 * @param a list of type values to look for
 
1031
                 * @param params an array of params to look for types in
 
1032
                 * @param valid_types an list of upper-case type values to look for
1019
1033
                 * @return a set of present type values
1020
1034
                 */
1021
1035
                private Set< String > extractTypes( String[] params,
1031
1045
                                // the specs!)
1032
1046
                                String[] parts = type_params[ a ].split( "," );
1033
1047
                                for( int i = 0; i < parts.length; i++ )
 
1048
                                        parts[ i ] = parts[ i ].toUpperCase( Locale.US );
 
1049
                                for( int i = 0; i < parts.length; i++ )
1034
1050
                                        if( valid_types.contains( parts[ i ] ) )
1035
1051
                                                types.add( parts[ i ] );
1036
1052
                        }