Skip to content

Commit

Permalink
Merge pull request #6 from Saxonica/character-escapes
Browse files Browse the repository at this point in the history
Output strings with \U escapes for non-ASCII characters
  • Loading branch information
ndw authored Sep 18, 2024
2 parents 7761011 + 5fc8127 commit 77380b3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ Much of the output is the result of experimentation and exploring the
Javadoc APIs. If you discover that xmldoclet produces output that
doesn’t conform to the schema, or if you think that the output is
incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmldoclet/issues).

## Change log

* **0.5.0** String constants now use “backslash-U” escapes for non-ASCII characters.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docletVersion=0.4.0
schemaVersion=0.4.0
docletVersion=0.5.0
schemaVersion=0.5.0
docletTitle=XmlDoclet
docletName=xmldoclet
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 4 additions & 0 deletions sample/src/main/java/org/example/AbstractClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example;

abstract public class AbstractClass implements TestInterface {
}
13 changes: 13 additions & 0 deletions sample/src/main/java/org/example/Implementation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.example;

public class Implementation extends AbstractClass {
@Override
public void foo() {
// nop
}

@Override
public void bar() {
// nop
}
}
5 changes: 5 additions & 0 deletions sample/src/main/java/org/example/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
* @author <a href="mailto:[email protected]">Norm Tovey-Walsh</a>
*/
public class Sample {
protected static final String cyrillicLower =
"\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438" +
"\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0441\u0443" +
"\u0444\u0445\u0446\u0447\u0448\u0449\u044b\u044d\u044e\u044f";

public static void main(String[] args) {
SampleRuntime runtime = new SampleRuntime();
runtime.run();
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/java/org/example/TestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void foo(Class<? extends Object> spoon) {
* @see <a href="https://example.org">Example.org</a>
* @param spoon the string {@link com.sun.source.doctree.DocTree}
* @throws IllegalAccessError when something goes wrong
* @throws NullPointerException: this is an error. No colon is allowed in the exception name.
* @throws NullPointerException this is an error. No colon is allowed in the exception name.
* @see jdk.javadoc.doclet.Doclet#init(Locale, Reporter)
* @see net.sf.saxon.s9api.Processor#getConfigurationProperty(Feature)
* @return something
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.saxonica.xmldoclet.scanners;

import com.saxonica.xmldoclet.utils.TypeUtils;
import com.saxonica.xmldoclet.builder.XmlProcessor;
import com.saxonica.xmldoclet.utils.TypeUtils;
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.ParamTree;
Expand Down Expand Up @@ -36,7 +36,21 @@ public void scan(DocTree tree) {
attr.put("value", element.getConstantValue().toString());
}
} else {
attr.put("value", element.getConstantValue().toString());
StringBuilder sb = new StringBuilder();
String value = element.getConstantValue().toString();
int offset = 0;
int length = value.length();
while (offset < length) {
char cur = value.charAt(offset);
if (cur < ' ' || cur > 0x7f) {
sb.append(String.format("\\u%04x", (int) cur));
} else {
sb.append(cur);
}
offset += Character.charCount(cur);
}

attr.put("value", sb.toString());
}
}

Expand Down

0 comments on commit 77380b3

Please sign in to comment.