You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by be...@apache.org on 2026/09/02 11:19:28 UTC
(fesod) branch main updated: refactor: extract sanitisation part for improved readability (#1061)
This is an automated email from the ASF dual-hosted git repository.
bengbengbalabalabeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fesod.git
The following commit(s) were added to refs/heads/main by this push:
new b8adc73f refactor: extract sanitisation part for improved readability (#1061)
b8adc73f is described below
commit b8adc73fd384155093c1769d6c53d312f9008cde
Author: Nikita Kuprins <61...@users.noreply.github.com>
AuthorDate: Wed Sep 2 14:19:16 2026 +0300
refactor: extract sanitisation part for improved readability (#1061)
* refactor: extract `sanitizeString` method for improved readability
* refactor: introduce `isEscapableChar` helper method
---
.../org/apache/fesod/sheet/util/DateUtils.java | 52 +++++++++++-----------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java b/fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java
index 58425caa..0d271455 100644
--- a/fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java
+++ b/fesod-sheet/src/main/java/org/apache/fesod/sheet/util/DateUtils.java
@@ -584,32 +584,8 @@ public class DateUtils {
if (StringUtils.isEmpty(formatString)) {
return false;
}
- String fs = formatString;
- final int length = fs.length();
- StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; i++) {
- char c = fs.charAt(i);
- if (i < length - 1) {
- char nc = fs.charAt(i + 1);
- if (c == '\\') {
- switch (nc) {
- case '-':
- case ',':
- case '.':
- case ' ':
- case '\\':
- // skip current '\' and continue to the next char
- continue;
- }
- } else if (c == ';' && nc == '@') {
- i++;
- // skip ";@" duplets
- continue;
- }
- }
- sb.append(c);
- }
- fs = sb.toString();
+
+ String fs = sanitizeString(formatString);
// short-circuit if it indicates elapsed time: [h], [m] or [s]
if (date_ptrn4.matcher(fs).matches()) {
@@ -649,6 +625,30 @@ public class DateUtils {
return result;
}
+ private static String sanitizeString(String fs) {
+ final int length = fs.length();
+ StringBuilder sb = new StringBuilder(length);
+ for (int i = 0; i < length; i++) {
+ char c = fs.charAt(i);
+ if (i < length - 1) {
+ char nc = fs.charAt(i + 1);
+ if (c == '\\' && isEscapableChar(nc)) {
+ continue;
+ } else if (c == ';' && nc == '@') {
+ i++;
+ // skip ";@" duplets
+ continue;
+ }
+ }
+ sb.append(c);
+ }
+ return sb.toString();
+ }
+
+ private static boolean isEscapableChar(char c) {
+ return c == '-' || c == ',' || c == '.' || c == ' ' || c == '\\';
+ }
+
/**
* Given a format ID this will check whether the format represents an internal excel date format or not.
*
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org