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

For #3: Fix handling empty attribute value strings #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/android/content/res/AXmlResourceParser.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ public String getAttributeValue(int index) {
int valueType=m_attributes[offset+ATTRIBUTE_IX_VALUE_TYPE];
if (valueType==TypedValue.TYPE_STRING) {
int valueString=m_attributes[offset+ATTRIBUTE_IX_VALUE_STRING];
return m_strings.getString(valueString);
String value = m_strings.getString(valueString);
if (value != null) {
return value;
}
}
int valueData=m_attributes[offset+ATTRIBUTE_IX_VALUE_DATA];
return "";//TypedValue.coerceToString(valueType,valueData);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/bigzhao/xml2axml/chunks/AttrChunk.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bigzhao.xml2axml.chunks;

import android.text.TextUtils;
import android.graphics.Color;

import com.bigzhao.xml2axml.ComplexConsts;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void preWrite() {

@Override
public void writeEx(IntWriter w) throws IOException {
w.write(startTagChunk.stringIndex(null,namespace));
w.write(startTagChunk.stringIndex(null, TextUtils.isEmpty(namespace) ? null : namespace));
w.write(startTagChunk.stringIndex(namespace,name));
//w.write(-1);
if (value.type==ValueType.STRING)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/bigzhao/xml2axml/chunks/StringPoolChunk.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,13 @@ public void addString(String namespace, String s){
public int stringIndex(String namespace, String s) {
namespace=preHandleString(namespace);
s=preHandleString(s);
if (TextUtils.isEmpty(s)) return -1;
if (s == null) return -1;
int l=rawStrings.size();
for (int i=0;i<l;++i){
StringItem item=rawStrings.get(i).origin;
if (s.equals(item.string)&&(TextUtils.isEmpty(namespace)||namespace.equals(item.namespace))) return i;
}
if (TextUtils.isEmpty(s)) return -1; // only if there is no empty string in the string pool
throw new RuntimeException("String: '"+s+"' not found");
//return -1;
}
Expand Down