/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-21 11:57:56 UTC
  • Revision ID: tim@ed.am-20121221115756-zm37hcmc2a3wht6x
handle empty lines in vCards properly; be less case sensitive; fixed some comment typos

Show diffs side-by-side

added added

removed removed

202
202
                                        buffer.limit() - buffer.position(), "US-ASCII" );
203
203
                        }
204
204
                        catch( UnsupportedEncodingException e ) {
205
 
                                // we know US-ASCII is supported, so appease the compiler...
 
205
                                // we know US-ASCII *is* supported, so appease the compiler...
206
206
                                line = "";
207
207
                        }
208
208
 
504
504
                        else
505
505
                        {
506
506
                                // name and params and the position in the buffer where the
507
 
                                // "value" part of the line start
 
507
                                // "value" part of the line starts
508
508
                                String name_and_params;
509
509
                                int pos;
510
510
 
540
540
                                }
541
541
                                else
542
542
                                {
 
543
                                        // skip empty lines
 
544
                                        if( line.trim().length() == 0 ) return;
 
545
 
543
546
                                        // get name and params from line, and since we're not
544
547
                                        // parsing a subsequent line in a multi-line, this should
545
548
                                        // not fail, or it's an error
574
577
                                                "FN", "ORG", "TITLE", "TEL", "EMAIL", "ADR", "LABEL" }
575
578
                                ) );
576
579
                                boolean is_interesting_field =
577
 
                                        interesting_fields.contains( name_param_parts[ 0 ] );
 
580
                                        interesting_fields.contains(
 
581
                                                name_param_parts[ 0 ].toUpperCase( Locale.US ) );
578
582
 
579
583
                                // parse encoding parameter
580
584
                                String encoding = checkParam( name_param_parts, "ENCODING" );
1059
1063
                        String type_params[] = checkParams( params, "TYPE" );
1060
1064
                        for( int a = 0; a < type_params.length; a++ )
1061
1065
                        {
1062
 
                                // check for a comma-separated list of types (why? this isn't in
1063
 
                                // the specs!)
 
1066
                                // check for a comma-separated list of types (why? I don't think
 
1067
                                // this is in the specs!)
1064
1068
                                String[] parts = type_params[ a ].split( "," );
1065
 
                                for( int i = 0; i < parts.length; i++ )
1066
 
                                        parts[ i ] = parts[ i ].toUpperCase( Locale.US );
1067
 
                                for( int i = 0; i < parts.length; i++ )
1068
 
                                        if( valid_types.contains( parts[ i ] ) )
1069
 
                                                types.add( parts[ i ] );
 
1069
                                for( int i = 0; i < parts.length; i++ ) {
 
1070
                                        String ucpart = parts[ i ].toUpperCase( Locale.US );
 
1071
                                        if( valid_types.contains( ucpart ) )
 
1072
                                                types.add( ucpart );
 
1073
                                }
1070
1074
                        }
1071
1075
 
1072
1076
                        // get 2.1-style type param
1073
1077
                        if( _version.equals( "2.1" ) ) {
1074
 
                                for( int i = 1; i < params.length; i++ )
1075
 
                                        if( valid_types.contains( params[ i ] ) )
1076
 
                                                types.add( params[ i ] );
 
1078
                                for( int i = 1; i < params.length; i++ ) {
 
1079
                                        String ucparam = params[ i ].toUpperCase( Locale.US );
 
1080
                                        if( valid_types.contains( ucparam ) )
 
1081
                                                types.add( ucparam );
 
1082
                                }
1077
1083
                        }
1078
1084
 
1079
1085
                        return types;