Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9469 accented letters and other utf8 characters in Stata ingest #9582

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -281,6 +281,20 @@ public String readString(int n) throws IOException {
}
return ret;
}

/*
* Same, but expecting potential Unicode characters.
*/
public String readUtfString(int n) throws IOException {

String ret = new String(readBytes(n), "UTF8");

// Remove the terminating and/or padding zero bytes:
if (ret.indexOf(0) > -1) {
return ret.substring(0, ret.indexOf(0));
}
return ret;
}

/*
* More complex helper methods for reading NewDTA "sections" ...
Expand Down
Expand Up @@ -687,7 +687,7 @@ private void readVariableLabels(DataReader reader) throws IOException {
reader.readOpeningTag(TAG_VARIABLE_LABELS);

for (int i = 0; i < dataTable.getVarQuantity(); i++) {
String variableLabel = reader.readString(DTAVersion == 117? 81: 321);
String variableLabel = reader.readUtfString(DTAVersion == 117? 81: 321);
logger.fine("variable " + i + ": label=" + variableLabel);
if ((variableLabel != null) && (!variableLabel.equals(""))) {
dataTable.getDataVariables().get(i).setLabel(variableLabel);
Expand Down Expand Up @@ -1213,7 +1213,7 @@ private void readValueLabels(DataReader reader) throws IOException {
}
label_length = (int)(label_end - label_offset);

category_value_labels[i] = new String(Arrays.copyOfRange(labelBytes, (int)label_offset, (int)label_end-1), "US-ASCII");
category_value_labels[i] = new String(Arrays.copyOfRange(labelBytes, (int)label_offset, (int)label_end-1), "UTF8");
total_label_bytes += label_length;
}

Expand Down