gnodet-bot commented on code in PR #29341:
URL: https://github.com/apache/camel/pull/29341#discussion_r4493890690


##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelJBangMojo.java:
##########
@@ -74,6 +76,44 @@ public static List<JBangModel.JBangOptionModel> 
parseConfigurationSource(String
         return parseConfigurationSource(new File(fileName));
     }
 
+    // a Java string literal, with its escapes
+    private static final Pattern STRING_LITERAL = 
Pattern.compile("\"((?:[^\"\\\\]|\\\\.)*)\"");
+
+    /**
+     * The value of a String attribute of an annotation. A value written as 
string literals joined with {@code +} (a
+     * long description) is joined here: Roaster gives it as the source text 
with the {@code +} in it.
+     */
+    static String stringValue(AnnotationSource<?> as, String name) {
+        String literal = as.getLiteralValue(name);
+        if (literal == null || literal.indexOf('+') < 0 || 
!literal.startsWith("\"")) {
+            return as.getStringValue(name);
+        }
+        StringBuilder sb = new StringBuilder();
+        Matcher m = STRING_LITERAL.matcher(literal);
+        while (m.find()) {
+            sb.append(unescape(m.group(1)));
+        }
+        return sb.toString();
+    }
+
+    private static String unescape(String text) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < text.length(); i++) {
+            char ch = text.charAt(i);
+            if (ch == '\\' && i + 1 < text.length()) {
+                char next = text.charAt(++i);
+                sb.append(switch (next) {
+                    case 'n' -> '\n';
+                    case 't' -> '\t';
+                    default -> next;

Review Comment:
   💡 **Nit:** The `unescape()` switch handles `\n` and `\t` but not `\r`. The 
`default` branch would map `\\r` to literal `r` rather than a carriage return. 
Unlikely to appear in `@Metadata` descriptions, but worth noting for 
completeness. Not blocking.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to