32
32
import java .util .Map ;
33
33
34
34
import io .swagger .v3 .oas .models .SpecVersion ;
35
- import org .apache .commons .lang3 .StringUtils ;
35
+ import java .util .stream .Collectors ;
36
+
36
37
import org .slf4j .Logger ;
37
38
import org .slf4j .LoggerFactory ;
38
39
import org .springdoc .core .properties .SpringDocConfigProperties ;
@@ -114,23 +115,24 @@ public String resolve(String parameterProperty, Locale locale) {
114
115
* Returns a string where all leading indentation has been removed from each line.
115
116
* It detects the smallest common indentation of all the lines in the input string,
116
117
* and removes it.
118
+ * If the input text is {@code null}, the method returns {@code null}.
117
119
*
118
- * @param text The original string with possible leading indentation.
119
- * @return The string with leading indentation removed from each line.
120
+ * @param text The original string with possible leading indentation.
121
+ * @return The string with the smallest common leading indentation removed from each line,
122
+ * or {@code null} if the input text is {@code null}.
120
123
*/
121
124
public String trimIndent (String text ) {
125
+ if (text == null ) {
126
+ return null ;
127
+ }
128
+ final String newLine = "\n " ;
129
+ String [] lines = text .split ("\\ r?\\ n" );
130
+ int minIndent = resolveMinIndent (lines );
122
131
try {
123
- if (text == null ) {
124
- return null ;
125
- }
126
- final String newLine = "\n " ;
127
- String [] lines = text .split (newLine );
128
- int minIndent = resolveMinIndent (lines );
129
132
return Arrays .stream (lines )
130
- .map (line -> line .substring (Math .min (line .length (), minIndent )))
131
- .reduce ((a , b ) -> a + newLine + b )
132
- .orElse (StringUtils .EMPTY );
133
- } catch (Exception ex ){
133
+ .map (line -> line .substring (Math .min (line .length (), minIndent )))
134
+ .collect (Collectors .joining (newLine ));
135
+ } catch (Exception ex ) {
134
136
LOGGER .warn (ex .getMessage ());
135
137
return text ;
136
138
}
@@ -239,4 +241,4 @@ public Map<String, Object> resolveExtensions(Locale locale, Map<String, Object>
239
241
else
240
242
return extensions ;
241
243
}
242
- }
244
+ }
0 commit comments