Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/annotations/Async.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ private Async() {
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
public @interface Execute {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public double getXValue() {
public double getValue() {
return mValue;
}
}
}
208 changes: 114 additions & 94 deletions CodenameOne/src/com/codename1/io/JSONSanitizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,69 +479,10 @@ void sanitize() {
break token_loop;
}

// Strip trailing comma to convert {"a":0,} -> {"a":0}
// and [1,2,3,] -> [1,2,3,]
switch (state) {
case BEFORE_VALUE:
insert(i, "null");
break;
case BEFORE_ELEMENT:
case BEFORE_KEY:
elideTrailingComma(i);
break;
case AFTER_KEY:
insert(i, ":null");
break;
case START_MAP:
case START_ARRAY:
case AFTER_ELEMENT:
case AFTER_VALUE:
break;
}

--bracketDepth;
char closeBracket = isMap[bracketDepth] ? '}' : ']';
if (ch != closeBracket) {
replace(i, i + 1, closeBracket);
}
state = bracketDepth == 0 || !isMap[bracketDepth - 1]
? State.AFTER_ELEMENT : State.AFTER_VALUE;
state = processClosingSquareBracket(state, i, ch);
break;
case ',':
if (bracketDepth == 0) {
throw new RuntimeException("Unbracketed comma");
}
// Convert comma elisions like [1,,3] to [1,null,3].
// [1,,3] in JS is an array that has no element at index 1
// according to the "in" operator so accessing index 1 will
// yield the special value "undefined" which is equivalent to
// JS's "null" value according to "==".
switch (state) {
// Normal
case AFTER_ELEMENT:
state = State.BEFORE_ELEMENT;
break;
case AFTER_VALUE:
state = State.BEFORE_KEY;
break;
// Array elision.
case START_ARRAY:
case BEFORE_ELEMENT:
insert(i, "null");
state = State.BEFORE_ELEMENT;
break;
// Ignore
case START_MAP:
case BEFORE_KEY:
case AFTER_KEY:
elide(i, i + 1);
break;
// Supply missing value.
case BEFORE_VALUE:
insert(i, "null");
state = State.BEFORE_KEY;
break;
}
state = processComma(state, i);
break;

case ':':
Expand All @@ -553,39 +494,7 @@ void sanitize() {
break;

case '/':
// Skip over JS-style comments since people like inserting them into
// data files and getting huffy with Crockford when he says no to
// versioning JSON to allow ignorable tokens.
int end = i + 1;
if (i + 1 < n) {
switch (jsonish.charAt(i + 1)) {
case '/':
end = n; // Worst case.
for (int j = i + 2; j < n; ++j) {
char cch = jsonish.charAt(j);
if (cch == '\n' || cch == '\r'
|| cch == '\u2028' || cch == '\u2029') {
end = j + 1;
break;
}
}
break;
case '*':
end = n;
if (i + 3 < n) {
for (int j = i + 2;
(j = jsonish.indexOf('/', j + 1)) >= 0; ) { //NOPMD AssignmentInOperand
if (jsonish.charAt(j - 1) == '*') {
end = j + 1;
break;
}
}
}
break;
}
}
elide(i, end);
i = end - 1;
i = processSlash(i, n);
break;

default:
Expand Down Expand Up @@ -709,6 +618,117 @@ void sanitize() {
}
}

private int processSlash(int i, int n) {
// Skip over JS-style comments since people like inserting them into
// data files and getting huffy with Crockford when he says no to
// versioning JSON to allow ignorable tokens.
int end = i + 1;
if (i + 1 < n) {
switch (jsonish.charAt(i + 1)) {
case '/':
end = n; // Worst case.
for (int j = i + 2; j < n; ++j) {
char cch = jsonish.charAt(j);
if (cch == '\n' || cch == '\r'
|| cch == '\u2028' || cch == '\u2029') {
end = j + 1;
break;
}
}
break;
case '*':
end = findStarEnd(i, n);
break;
default:
break;
}
}
elide(i, end);
i = end - 1;
return i;
}

private int findStarEnd(int i, int n) {
if (i + 3 < n) {
for (int j = i + 2; (j = jsonish.indexOf('/', j + 1)) >= 0; ) { //NOPMD AssignmentInOperand
if (jsonish.charAt(j - 1) == '*') {
n = j + 1;
break;
}
}
}
return n;
}

private State processComma(State state, int i) {
if (bracketDepth == 0) {
throw new RuntimeException("Unbracketed comma");
}
// Convert comma elisions like [1,,3] to [1,null,3].
// [1,,3] in JS is an array that has no element at index 1
// according to the "in" operator so accessing index 1 will
// yield the special value "undefined" which is equivalent to
// JS's "null" value according to "==".
switch (state) {
// Normal
case AFTER_ELEMENT:
state = State.BEFORE_ELEMENT;
break;
case AFTER_VALUE:
state = State.BEFORE_KEY;
break;
// Array elision.
case START_ARRAY:
case BEFORE_ELEMENT:
insert(i, "null");
state = State.BEFORE_ELEMENT;
break;
// Ignore
case START_MAP:
case BEFORE_KEY:
case AFTER_KEY:
elide(i, i + 1);
break;
// Supply missing value.
case BEFORE_VALUE:
insert(i, "null");
state = State.BEFORE_KEY;
break;
}
return state;
}

private State processClosingSquareBracket(State state, int i, char ch) {
// Strip trailing comma to convert {"a":0,} -> {"a":0}
// and [1,2,3,] -> [1,2,3,]
switch (state) {
case BEFORE_VALUE:
insert(i, "null");
break;
case BEFORE_ELEMENT:
case BEFORE_KEY:
elideTrailingComma(i);
break;
case AFTER_KEY:
insert(i, ":null");
break;
case START_MAP:
case START_ARRAY:
case AFTER_ELEMENT:
case AFTER_VALUE:
break;
}

--bracketDepth;
char closeBracket = isMap[bracketDepth] ? '}' : ']';
if (ch != closeBracket) {
replace(i, i + 1, closeBracket);
}
state = bracketDepth == 0 || !isMap[bracketDepth - 1]
? State.AFTER_ELEMENT : State.AFTER_VALUE;
return state;
}

/**
* Ensures that the output corresponding to {@code jsonish[start:end]} is a
* valid JSON string that has the same meaning when parsed by Javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ public MalformedURLException() {
public MalformedURLException(String message) {
super(message);
}
}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/io/tar/TarEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@ public void parseTarHeader(byte[] bh) {

header.devMinor = (int) Octal.parseOctal(bh, offset, TarHeader.DEVLEN);
}
}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/io/tar/TarHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ public static int getNameBytes(StringBuffer name, byte[] buf, int offset, int le
return offset + length;
}

}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/javascript/JSException.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ class JSException extends RuntimeException {
public JSException(String msg) {
super(msg);
}
}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/javascript/JSFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
*/
public interface JSFunction {
void apply(JSObject self, Object[] args);
}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/l10n/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public abstract class Format implements Cloneable {
* @throws ParseException if the source could not be parsed.
*/
public abstract Object parseObject(String source) throws ParseException;
}
}
3 changes: 1 addition & 2 deletions CodenameOne/src/com/codename1/payment/Purchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ private Receipt getFirstReceiptExpiringAfter(Receipt[] receipts, Date publishDat
&& r.getPurchaseDate().getTime() <= publishDate.getTime()
&& r.getExpiryDate().getTime() >= publishDate.getTime()
&& (r.getCancellationDate() == null
|| r.getCancellationDate().getTime() >= publishDate.getTime()
)) {
|| r.getCancellationDate().getTime() >= publishDate.getTime())) {
// Exact match in range.
return r;
}
Expand Down
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/processing/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ Object evaluate(List elements)
*/
Object evaluate(StructuredContent element)
throws IllegalArgumentException;
}
}
5 changes: 3 additions & 2 deletions CodenameOne/src/com/codename1/ui/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,13 @@ public class Component implements Animation, StyleListener, Editable {
/**
* The width of the component when the {@link #cachedShadowImage} was created.
*/
private int cachedShadowWidth,
private int cachedShadowWidth;

/**
* The height of the component when the {@link #cachedShadowImage} was created.
*/
cachedShadowHeight;
private int cachedShadowHeight;

/**
* Flag to indicate whether the component has elevation.
*/
Expand Down
3 changes: 1 addition & 2 deletions CodenameOne/src/com/codename1/ui/ComponentImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,4 @@ protected Image getInternal() {

}


}
}
6 changes: 2 additions & 4 deletions CodenameOne/src/com/codename1/ui/layouts/GroupLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,7 @@ Group addSpring(Spring spring) {
void setSize(int axis, int origin, int size) {
super.setSize(axis, origin, size);
if (size == UNSET) {
for (int counter = springs.size() - 1; counter >= 0;
counter--) {
for (int counter = springs.size() - 1; counter >= 0; counter--) {
getSpring(counter).setSize(axis, origin, size);
}
} else {
Expand Down Expand Up @@ -1893,8 +1892,7 @@ int operator(int a, int b) {
void setValidSize(int axis, int origin, int size) {
int pref = getPreferredSize(axis);
if (size == pref) {
for (int counter = 0, max = springs.size(); counter < max;
counter++) {
for (int counter = 0, max = springs.size(); counter < max; counter++) {
Spring spring = getSpring(counter);
int springPref = spring.getPreferredSize(axis);
spring.setSize(axis, origin, springPref);
Expand Down
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/ui/layouts/mig/AC.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,4 @@ private void makeSize(int sz) {
}
}
}
}
}
4 changes: 2 additions & 2 deletions CodenameOne/src/com/codename1/ui/layouts/mig/BoundSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public BoundSize(UnitValue minMaxPref, String createString) {
* @param max The maximum size. May be <code>null</code>.
* @param createString The string used to create the BoundsSize.
*/
public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, String createString) // Bound to old delegate!!!!!
{
public BoundSize(UnitValue min, UnitValue preferred, UnitValue max, String createString) {
// Bound to old delegate!!!!!
this(min, preferred, max, false, createString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,4 @@ public interface ComponentWrapper {
* @since 5.0
*/
int getContentBias();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,8 @@ private static int startsWithLenient(String s, String[] matches, int[] minChars,
* found.
*/
private static int startsWithLenient(String s, String match, int minChars, boolean acceptTrailing) {
if (s.charAt(0) != match.charAt(0)) // Fast sanity check.
{
if (s.charAt(0) != match.charAt(0)) {
// Fast sanity check.
return -1;
}

Expand All @@ -1442,8 +1442,8 @@ private static int startsWithLenient(String s, String match, int minChars, boole
int mSz = match.length();
int sIx = 0;
for (int mIx = 0; mIx < mSz; sIx++, mIx++) {
while (sIx < sSz && (s.charAt(sIx) == ' ' || s.charAt(sIx) == '_')) // Disregard spaces and _
{
while (sIx < sSz && (s.charAt(sIx) == ' ' || s.charAt(sIx) == '_')) {
// Disregard spaces and _
sIx++;
}

Expand Down
Loading
Loading