Skip to content

Commit 77380b3

Browse files
authored
Merge pull request #6 from Saxonica/character-escapes
Output strings with \U escapes for non-ASCII characters
2 parents 7761011 + 5fc8127 commit 77380b3

File tree

8 files changed

+46
-6
lines changed

8 files changed

+46
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ Much of the output is the result of experimentation and exploring the
117117
Javadoc APIs. If you discover that xmldoclet produces output that
118118
doesn’t conform to the schema, or if you think that the output is
119119
incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmldoclet/issues).
120+
121+
## Change log
122+
123+
* **0.5.0** String constants now use “backslash-U” escapes for non-ASCII characters.

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docletVersion=0.4.0
2-
schemaVersion=0.4.0
1+
docletVersion=0.5.0
2+
schemaVersion=0.5.0
33
docletTitle=XmlDoclet
44
docletName=xmldoclet

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.example;
2+
3+
abstract public class AbstractClass implements TestInterface {
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.example;
2+
3+
public class Implementation extends AbstractClass {
4+
@Override
5+
public void foo() {
6+
// nop
7+
}
8+
9+
@Override
10+
public void bar() {
11+
// nop
12+
}
13+
}

sample/src/main/java/org/example/Sample.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
* @author <a href="mailto:[email protected]">Norm Tovey-Walsh</a>
1313
*/
1414
public class Sample {
15+
protected static final String cyrillicLower =
16+
"\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438" +
17+
"\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0441\u0443" +
18+
"\u0444\u0445\u0446\u0447\u0448\u0449\u044b\u044d\u044e\u044f";
19+
1520
public static void main(String[] args) {
1621
SampleRuntime runtime = new SampleRuntime();
1722
runtime.run();

sample/src/main/java/org/example/TestClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void foo(Class<? extends Object> spoon) {
9292
* @see <a href="https://example.org">Example.org</a>
9393
* @param spoon the string {@link com.sun.source.doctree.DocTree}
9494
* @throws IllegalAccessError when something goes wrong
95-
* @throws NullPointerException: this is an error. No colon is allowed in the exception name.
95+
* @throws NullPointerException this is an error. No colon is allowed in the exception name.
9696
* @see jdk.javadoc.doclet.Doclet#init(Locale, Reporter)
9797
* @see net.sf.saxon.s9api.Processor#getConfigurationProperty(Feature)
9898
* @return something

xmldoclet/src/main/java/com/saxonica/xmldoclet/scanners/XmlVariableElement.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.saxonica.xmldoclet.scanners;
22

3-
import com.saxonica.xmldoclet.utils.TypeUtils;
43
import com.saxonica.xmldoclet.builder.XmlProcessor;
4+
import com.saxonica.xmldoclet.utils.TypeUtils;
55
import com.sun.source.doctree.DocCommentTree;
66
import com.sun.source.doctree.DocTree;
77
import com.sun.source.doctree.ParamTree;
@@ -36,7 +36,21 @@ public void scan(DocTree tree) {
3636
attr.put("value", element.getConstantValue().toString());
3737
}
3838
} else {
39-
attr.put("value", element.getConstantValue().toString());
39+
StringBuilder sb = new StringBuilder();
40+
String value = element.getConstantValue().toString();
41+
int offset = 0;
42+
int length = value.length();
43+
while (offset < length) {
44+
char cur = value.charAt(offset);
45+
if (cur < ' ' || cur > 0x7f) {
46+
sb.append(String.format("\\u%04x", (int) cur));
47+
} else {
48+
sb.append(cur);
49+
}
50+
offset += Character.charCount(cur);
51+
}
52+
53+
attr.put("value", sb.toString());
4054
}
4155
}
4256

0 commit comments

Comments
 (0)