/android/export-contacts

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

« back to all changes in this revision

Viewing changes to src/am/ed/exportcontacts/VcardExporter.java

  • Committer: Tim Marston
  • Date: 2013-06-22 19:31:44 UTC
  • Revision ID: tim@ed.am-20130622193144-0lo7w92qagow0kmu
minor style tweaks

Show diffs side-by-side

added added

removed removed

4
4
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export 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/export-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
268
268
                                case ContactData.TYPE_WORK:
269
269
                                        types.add( "WORK" ); break;
270
270
                                }
 
271
                                // we use LABEL because is accepts formatted text (whereas ADR
 
272
                                // expects semicolon-delimited fields with specific purposes)
271
273
                                out.append( fold( "LABEL" +
272
274
                                        ( types.size() > 0? ";TYPE=" + join( types, "," ) : "" ) +
273
275
                                        ":" + escape( addresses.get( a ).getAddress() ) ) + "\n" );
283
285
                // append footer
284
286
                out.append( "END:VCARD\n" );
285
287
 
 
288
                // replace '\n' with "\r\n" (spec requires CRLF)
 
289
                int pos = 0;
 
290
                while( true ) {
 
291
                        pos = out.indexOf( "\n", pos );
 
292
                        if( pos == -1 ) break;
 
293
                        out.replace( pos, pos + 1, "\r\n" );
 
294
 
 
295
                        // skip our inserted string
 
296
                        pos += 2;
 
297
                }
 
298
 
286
299
                // write to file
287
300
                try {
288
301
                        _ostream.write( out.toString().getBytes() );