Skip to content

Commit

Permalink
unknown string pool reference coder #18
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Jul 20, 2023
1 parent 0721784 commit 0adc206
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/main/java/com/reandroid/arsc/coder/CoderUnknownStringRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.coder;

import com.reandroid.arsc.value.ValueType;
import com.reandroid.utils.HexUtil;

/**
* Handles when the string reference is not available on string pool
* */
public class CoderUnknownStringRef extends Coder {

@Override
public EncodeResult encode(String text) {
if(text == null || text.length() != LENGTH){
return null;
}
String prefix = PREFIX;
if(!text.startsWith(prefix)){
return null;
}
Integer value = parseHex(text.substring(prefix.length() + 1));
if(value != null){
return new EncodeResult(ValueType.STRING, value);
}
return null;
}
@Override
public String decode(int data) {
return HexUtil.toHex8(PREFIX, data);
}
@Override
public ValueType getValueType() {
return ValueType.STRING;
}
@Override
boolean canStartWith(char first) {
return first == PREFIX_CHAR;
}
public static final CoderUnknownStringRef INS = new CoderUnknownStringRef();

private static final char PREFIX_CHAR = 's';
private static final String PREFIX = "string-reference@0x";
private static final int LENGTH = PREFIX.length() + 8;
}

0 comments on commit 0adc206

Please sign in to comment.