/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: 2013-01-06 18:12:50 UTC
  • Revision ID: tim@ed.am-20130106181250-ymz5p33p1q7o06c4
bump version no. and update NEWS

Show diffs side-by-side

added added

removed removed

4
4
 * Copyright (C) 2009 to 2011 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
 
7
 * to as "this program"). For more information, see
8
8
 * http://ed.am/dev/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
133
133
                        boolean in_vcard = false;
134
134
                        while( ( line = reader.readLine() ) != null )
135
135
                        {
136
 
                                if( !in_vcard )
137
 
                                {
 
136
                                if( !in_vcard ) {
138
137
                                        // look for vcard beginning
139
 
                                        if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VCARD.*" ) ) {
 
138
                                        if( line.matches( "^BEGIN[ \t]*:[ \t]*VCARD.*$" ) ) {
140
139
                                                in_vcard = true;
141
140
                                                _vcard_count++;
142
141
                                        }
143
 
                                        // check for vMsg files
144
 
                                        else if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VMSG.*" ) ) {
145
 
                                                showError( getText( R.string.error_vcf_vmsgfile )
146
 
                                                        + file.getName() );
147
 
                                        }
148
142
                                }
149
 
                                else if( line.matches( "(?i)END[ \t]*:[ \t]*VCARD.*" ) )
 
143
                                else if( line.matches( "^END[ \t]*:[ \t]*VCARD.*$" ) )
150
144
                                        in_vcard = false;
151
145
                        }
152
146
 
209
203
 
210
204
                        if( vcard == null ) {
211
205
                                // look for vcard beginning
212
 
                                if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VCARD.*" ) ) {
 
206
                                if( line.matches( "^BEGIN[ \t]*:[ \t]*VCARD.*$" ) ) {
213
207
                                        setProgress( _progress++ );
214
208
                                        vcard = new Vcard();
215
209
                                        vcard_start_line = cli.getLineNumber();
217
211
                        }
218
212
                        else {
219
213
                                // look for vcard content or ending
220
 
                                if( line.matches( "(?i)END[ \t]*:[ \t]*VCARD.*" ) )
 
214
                                if( line.matches( "^END[ \t]*:[ \t]*VCARD.*$" ) )
221
215
                                {
222
216
                                        // finalise the vcard/contact
223
217
                                        try {
273
267
                                                        finish( ACTION_ABORT );
274
268
                                                }
275
269
 
276
 
                                                // Although we're continuing, we still need to abort
277
 
                                                // this vCard.  Further lines will be ignored until we
 
270
                                                // although we're continuing, we still need to abort
 
271
                                                // this vCard. Further lines will be ignored until we
278
272
                                                // get to another BEGIN:VCARD line.
279
273
                                                vcard = null;
280
274
                                        }
281
275
                                        catch( Vcard.SkipImportException e ) {
282
276
                                                skipContact();
283
 
                                                // Abort this vCard.  Further lines will be ignored until
 
277
                                                // abort this vCard. Further lines will be ignored until
284
278
                                                // we get to another BEGIN:VCARD line.
285
279
                                                vcard = null;
286
280
                                        }
752
746
                        {
753
747
                                String str = parts.get( a );
754
748
 
755
 
                                // Look for parts that end in an escape character, but ignore
756
 
                                // the final part.  We've already detected escape chars at the
 
749
                                // look for parts that end in an escape character, but ignore
 
750
                                // the final part. We've already detected escape chars at the
757
751
                                // end of the final part in parseLine() and handled multi-lines
758
752
                                // accordingly.
759
753
                                if( a < parts.size() - 1 &&
1042
1036
 
1043
1037
                /**
1044
1038
                 * Amongst the params, find the value of the first, only, of any with
1045
 
                 * the specified name.
1046
 
                 *
 
1039
                 * the specified name
1047
1040
                 * @param params
1048
1041
                 * @param name
1049
1042
                 * @return a value, or null
1055
1048
                }
1056
1049
 
1057
1050
                /**
1058
 
                 * Amongst the params, find the values of any with the specified name.
1059
 
                 *
 
1051
                 * Amongst the params, find the values of any with the specified name
1060
1052
                 * @param params
1061
1053
                 * @param name
1062
1054
                 * @return an array of values, or null
1078
1070
                }
1079
1071
 
1080
1072
                /**
1081
 
                 * Amongst the params, return any type values present.  For v2.1 vCards,
1082
 
                 * those types are just parameters.  For v3.0, they are prefixed with
1083
 
                 * "TYPE=".  There may also be multiple type parameters.
1084
 
                 *
 
1073
                 * Amongst the params, return any type values present. For v2.1 vCards,
 
1074
                 * those types are just parameters. For v3.0, they are prefixed with
 
1075
                 * "TYPE=". There may also be multiple type parameters.
1085
1076
                 * @param params an array of params to look for types in
1086
1077
                 * @param valid_types an list of upper-case type values to look for
1087
1078
                 * @return a set of present type values
1139
1130
                                else if( ch == '=' && i == in.limit() - 1 )
1140
1131
                                {
1141
1132
                                        // we found a '=' at the end of a line signifying a multi-
1142
 
                                        // line string, so we don't add it
 
1133
                                        // line string, so we don't add it.
1143
1134
                                        another = true;
1144
1135
                                        continue;
1145
1136
                                }