Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b29c53eb authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Small fix around intermideate charset (ISO-8859-1).

After a few investigation, it is found that ISO-8859-1 is confirmed to be the
best charset for that use.

Modify comment so that we explicitly mention it.

Change-Id: I16e487fab33964a1665a1dd6991f2e8598f8895e
parent 4e0b1a7e
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -43,15 +43,20 @@ public class VCardConfig {
     * The charset used during import.
     * </p>
     * <p>
     * We cannot determine which charset should be used to interpret a given vCard file
     * at first, while we have to decode sime encoded data (e.g. BASE64) to binary.
     * In order to avoid "misinterpretation" of charset as much as possible,
     * "ISO-8859-1" (a.k.a Latin-1) is first used for reading a stream.
     * When charset is specified in a property (with "CHARSET=..." parameter),
     * We cannot determine which charset should be used to interpret lines in vCard,
     * while Java requires us to specify it when InputStream is used.
     * We need to rely on the mechanism due to some performance reason.
     * </p>
     * <p>
     * In order to avoid "misinterpretation" of charset and lose any data in vCard,
     * "ISO-8859-1" is first used for reading the stream.
     * When a charset is specified in a property (with "CHARSET=..." parameter),
     * the string is decoded to raw bytes and encoded into the specific charset,
     * assuming "ISO-8859-1" is able to map "all" 8bit characters to some unicode,
     * and it has 1 to 1 mapping in all 8bit characters.
     * If the assumption is not correct, this setting will cause some bug.
     * </p>
     * <p>
     * Unicode specification there's a one to one mapping between each byte in ISO-8859-1
     * and a codepoint, and Java specification requires runtime must have the charset.
     * Thus, ISO-8859-1 is one effective mapping for intermediate mapping.
     * </p>
     */
    public static final String DEFAULT_INTERMEDIATE_CHARSET = "ISO-8859-1";
+2 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class VCardEntryConstructor implements VCardInterpreter {
    private final List<VCardEntryHandler> mEntryHandlers = new ArrayList<VCardEntryHandler>();

    public VCardEntryConstructor() {
        this(VCardConfig.VCARD_TYPE_V21_GENERIC, null, null, false);
        this(VCardConfig.VCARD_TYPE_V21_GENERIC, null);
    }

    public VCardEntryConstructor(final int vcardType) {
@@ -85,7 +85,7 @@ public class VCardEntryConstructor implements VCardInterpreter {
    }

    /**
     * @hide
     * @hide Just for testing.
     */
    public VCardEntryConstructor(final int vcardType, final Account account,
            final String inputCharset, final boolean strictLineBreakParsing) {
+7 −13
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.vcard;

import android.text.TextUtils;
import android.util.Log;

import com.android.vcard.exception.VCardAgentNotSupportedException;
@@ -64,12 +63,12 @@ import java.util.Set;
        }
    }

    private static final String sDefaultEncoding = "8BIT";
    private static final String DEFAULT_ENCODING = "8BIT";

    protected boolean mCanceled;
    protected VCardInterpreter mInterpreter;

    protected final String mImportCharset;
    protected final String mIntermediateCharset;

    /**
     * <p>
@@ -136,20 +135,15 @@ import java.util.Set;
    private long mTimeHandleBase64;

    public VCardParserImpl_V21() {
        this(VCardConfig.VCARD_TYPE_DEFAULT, null);
        this(VCardConfig.VCARD_TYPE_DEFAULT);
    }

    public VCardParserImpl_V21(int vcardType) {
        this(vcardType, null);
    }

    public VCardParserImpl_V21(int vcardType, String importCharset) {
        if ((vcardType & VCardConfig.FLAG_TORELATE_NEST) != 0) {
            mNestCount = 1;
        }

        mImportCharset = (!TextUtils.isEmpty(importCharset) ? importCharset :
            VCardConfig.DEFAULT_INTERMEDIATE_CHARSET);
        mIntermediateCharset =  VCardConfig.DEFAULT_INTERMEDIATE_CHARSET;
    }

    /**
@@ -385,7 +379,7 @@ import java.util.Set;
     * "AGENT" [params] ":" vcard CRLF
     */
    protected boolean parseItem() throws IOException, VCardException {
        mCurrentEncoding = sDefaultEncoding;
        mCurrentEncoding = DEFAULT_ENCODING;

        final String line = getNonEmptyLine();
        long start = System.currentTimeMillis();
@@ -928,7 +922,7 @@ import java.util.Set;
    }

    protected String getDefaultEncoding() {
        return sDefaultEncoding;
        return DEFAULT_ENCODING;
    }


@@ -938,7 +932,7 @@ import java.util.Set;
            throw new NullPointerException("InputStream must not be null.");
        }

        final InputStreamReader tmpReader = new InputStreamReader(is, mImportCharset);
        final InputStreamReader tmpReader = new InputStreamReader(is, mIntermediateCharset);
        if (VCardConfig.showPerformanceLog()) {
            mReader = new CustomBufferedReader(tmpReader);
        } else {
+1 −5
Original line number Diff line number Diff line
@@ -46,11 +46,7 @@ import java.util.Set;
    }

    public VCardParserImpl_V30(int vcardType) {
        super(vcardType, null);
    }

    public VCardParserImpl_V30(int vcardType, String importCharset) {
        super(vcardType, importCharset);
        super(vcardType);
    }

    @Override
+0 −4
Original line number Diff line number Diff line
@@ -98,10 +98,6 @@ public final class VCardParser_V21 implements VCardParser {
        mVCardParserImpl = new VCardParserImpl_V21(vcardType);
    }

    public VCardParser_V21(int parseType, String inputCharset) {
        mVCardParserImpl = new VCardParserImpl_V21(parseType, null);
    }

    public void parse(InputStream is, VCardInterpreter interepreter)
            throws IOException, VCardException {
        mVCardParserImpl.parse(is, interepreter);
Loading