Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated description #1067

Merged
merged 2 commits into from
Dec 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void generate(String outputFile, String inclusionPattern, String date) {
if (!pattern.matcher(name).matches()) {
return;
}
String description = String.valueOf(propertyItem.get("description"));
String description = replaceQuotes(String.valueOf(propertyItem.get("description")));
String defaultValue = String.valueOf(propertyItem.get("defaultValue"));
descriptions.put(name, defaultValue == null || defaultValue.equals("null") ? description
: description + " The default value is " + "`" + defaultValue + "`" + ".");
Expand Down Expand Up @@ -154,6 +154,62 @@ protected List<Resource> getSpringConfigurationMetadataJsonFilesInClasspath() th
}).collect(Collectors.toList());
}

/**
* Replace single/double quotes with backticks, ignoring possessive and nested
* cases.
*/
private String replaceQuotes(String description) {
StringBuilder result = new StringBuilder();
int n = description.length();
boolean insideSingleQuote = false;
boolean insideDoubleQuote = false;
boolean insideBacktick = false;

for (int i = 0; i < n; i++) {
char currentChar = description.charAt(i);
if (currentChar == '`') {
insideBacktick = !insideBacktick;
result.append(currentChar);
continue;
}
if (!insideBacktick) {
// skip 's
if (i + 1 < n && currentChar == '\'' && description.charAt(i + 1) == 's' && i > 0
&& Character.isLetter(description.charAt(i - 1))) {
result.append(currentChar);
continue;
}
if (currentChar == '\'' && !insideDoubleQuote) {
if (insideSingleQuote) {
result.append('`');
insideSingleQuote = false;
}
else {
result.append('`');
insideSingleQuote = true;
}
}
else if (currentChar == '"' && !insideSingleQuote) {
if (insideDoubleQuote) {
result.append('`');
insideDoubleQuote = false;
}
else {
result.append('`');
insideDoubleQuote = true;
}
}
else {
result.append(currentChar);
}
}
else {
result.append(currentChar);
}
}
return result.toString();
}

/**
* Padding the string to the required length.
* @param string the string to padding
Expand Down
Loading