-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support of mediawiki localization files for magicword int
- Loading branch information
Showing
12 changed files
with
766 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
License Information, 2023 Livio (javalc6) | ||
Feel free to modify, re-use this software, please give appropriate | ||
credit by referencing this Github repository. | ||
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. | ||
IMPORTANT NOTICE | ||
Note that this software is freeware and it is not designed, licensed or | ||
intended for use in mission critical, life support and military purposes. | ||
The use of this software is at the risk of the user. | ||
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS. | ||
*/ | ||
package json; | ||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
/* JSONArray holds a JSON array | ||
array ::= '[' [ value ( ',' value )* ] ']' | ||
int size() returns number of elements | ||
JSONValue get(idx) returns element at index idx | ||
Object toJava();//return Java value | ||
String toString();//return JSON value | ||
boolean equals(Object o)//check equal | ||
*/ | ||
final public class JSONArray extends JSONValue { | ||
final ArrayList<JSONValue> value = new ArrayList<>(); | ||
|
||
public JSONArray(ArrayList<Object> val) {//Java oriented constructor | ||
for (Object element: val) { | ||
if (element == null) | ||
value.add(null); | ||
else if (element instanceof Boolean) { | ||
value.add(new JSONBoolean((Boolean) element)); | ||
} else if (element instanceof BigDecimal) { | ||
value.add(new JSONNumber((BigDecimal) element)); | ||
} else if (element instanceof String) { | ||
try { | ||
value.add(new JSONString((String) element, false)); | ||
} catch (JSONException je) { | ||
//never happen | ||
} | ||
} else if (element instanceof ArrayList) { | ||
value.add(new JSONArray((ArrayList<Object>) element)); | ||
} else if (element instanceof LinkedHashMap) { | ||
value.add(new JSONObject((LinkedHashMap<String, Object>) element)); | ||
} | ||
} | ||
} | ||
|
||
public int size() { | ||
return value.size(); | ||
} | ||
|
||
public JSONValue get(int idx) { | ||
return value.get(idx); | ||
} | ||
|
||
public JSONArray(String str) throws JSONException {//constructor parsing a string representing a JSON array | ||
Scanner scanner = new Scanner(str); | ||
_parse(scanner); | ||
if (!scanner.eos()) throw new JSONException("parsing error due to unexpected trailing characters"); | ||
} | ||
|
||
public JSONArray(Scanner scanner) throws JSONException {//constructor using Scanner, note that parsing stops after a json value is found, even if extra characters remain in scanner | ||
_parse(scanner); | ||
} | ||
|
||
private void _parse(Scanner scanner) throws JSONException { | ||
Character ch = scanner.getChar("[", true, true); | ||
while (((ch = scanner.getChar(true, true)) != null) && ((ch = scanner.getChar("]", true, false)) == null)) { | ||
value.add(JSONValue.parse(scanner)); | ||
ch = scanner.getChar(",]", true, true); | ||
if (ch == ']') | ||
break; | ||
} | ||
if (ch == null) throw new JSONException("parsing error, expecting ]"); | ||
} | ||
|
||
public Object toJava() { | ||
ArrayList<Object> result = new ArrayList<>(); | ||
for (JSONValue element: value) { | ||
result.add(element == null ? "null" : element.toJava()); | ||
} | ||
return result; | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder().append('['); | ||
boolean first = true; | ||
for (JSONValue element: value) { | ||
if (first) | ||
first = false; | ||
else sb.append(','); | ||
sb.append(element == null ? "null" : element.toString()); | ||
} | ||
sb.append(']'); | ||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
License Information, 2023 Livio (javalc6) | ||
Feel free to modify, re-use this software, please give appropriate | ||
credit by referencing this Github repository. | ||
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. | ||
IMPORTANT NOTICE | ||
Note that this software is freeware and it is not designed, licensed or | ||
intended for use in mission critical, life support and military purposes. | ||
The use of this software is at the risk of the user. | ||
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS. | ||
*/ | ||
package json; | ||
|
||
/* JSONBoolean holds a JSON boolean | ||
booelan = 'false' | 'true' | ||
*/ | ||
final public class JSONBoolean extends JSONValue { | ||
final boolean value; | ||
|
||
public JSONBoolean(boolean val) {//Java oriented constructor | ||
value = val; | ||
} | ||
|
||
public Object toJava() { | ||
return value; | ||
} | ||
|
||
public String toString() { | ||
return value ? "true" : "false"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package json; | ||
|
||
public final class JSONException extends Exception { | ||
public JSONException(Exception e) { | ||
super(e); | ||
} | ||
|
||
public JSONException(String s) { | ||
super(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
License Information, 2023 Livio (javalc6) | ||
Feel free to modify, re-use this software, please give appropriate | ||
credit by referencing this Github repository. | ||
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. | ||
IMPORTANT NOTICE | ||
Note that this software is freeware and it is not designed, licensed or | ||
intended for use in mission critical, life support and military purposes. | ||
The use of this software is at the risk of the user. | ||
DO NOT USE THIS SOFTWARE IF YOU DON'T AGREE WITH STATED CONDITIONS. | ||
*/ | ||
package json; | ||
import java.math.BigDecimal; | ||
|
||
/* JSONNumber holds a JSON number | ||
number ::= [ '-' ] int [ frac ] [ exp ] | ||
int ::= '0' | ( digit1-9 digit* ) | ||
frac ::= '.' digit+ | ||
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | ||
exp ::= ('e' | 'E') [ '+' | '-' ] digit+ | ||
Object toJava();//return Java value | ||
String toString();//return JSON value | ||
boolean equals(Object o)//check equal | ||
*/ | ||
final public class JSONNumber extends JSONValue { | ||
BigDecimal value; | ||
|
||
public JSONNumber(BigDecimal val) {//Java oriented constructor | ||
value = val; | ||
} | ||
|
||
public JSONNumber(String str) throws JSONException {//constructor parsing a string representing a JSON number | ||
Scanner scanner = new Scanner(str); | ||
_parse(scanner); | ||
if (!scanner.eos()) throw new JSONException("parsing error due to unexpected trailing characters"); | ||
} | ||
|
||
public JSONNumber(Scanner scanner) throws JSONException {//constructor using Scanner, note that parsing stops after a json value is found, even if extra characters remain in scanner | ||
_parse(scanner); | ||
} | ||
|
||
private void _parse(Scanner scanner) throws JSONException { | ||
StringBuilder sb = new StringBuilder(); | ||
Character ch = scanner.getChar("-0123456789", true, true); | ||
if (ch == '-') { | ||
sb.append(ch); | ||
ch = scanner.getChar("0123456789", false, true); | ||
} | ||
if (ch == '0') { | ||
sb.append(ch); | ||
} else if (ch > '0' && ch <= '9') { | ||
sb.append(ch); | ||
while ((ch = scanner.getChar("0123456789", false, false)) != null) { | ||
sb.append(ch); | ||
} | ||
} | ||
|
||
ch = scanner.getChar(".eE", false, false); | ||
if ((ch != null) && ch == '.') { | ||
int decimals = 0; | ||
sb.append(ch); | ||
while ((ch = scanner.getChar("0123456789", false, false)) != null) { | ||
decimals++; | ||
sb.append(ch); | ||
} | ||
if (decimals == 0) throw new JSONException("parsing error"); | ||
ch = scanner.getChar("eE", false, false); | ||
} | ||
if (ch != null) {//if ch != null then ch is either 'e' or 'E' | ||
sb.append(ch); | ||
ch = scanner.getChar("+-", false, false); | ||
if (ch != null) | ||
sb.append(ch); | ||
boolean first = true; | ||
while ((ch = scanner.getChar("0123456789", false, first)) != null) { | ||
sb.append(ch); | ||
first = false; | ||
} | ||
} | ||
value = new BigDecimal(sb.toString()); | ||
} | ||
|
||
public Object toJava() { | ||
return value; | ||
} | ||
|
||
public String toString() { | ||
return value.toString(); | ||
} | ||
} |
Oops, something went wrong.