From 272585bf3c2ff7181c21de093f70e2a14ed3551f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 1 Feb 2023 16:17:37 +0100 Subject: [PATCH] Java: don't generate past participle name suggestion when the word contains anything other than an ascii letter GitOrigin-RevId: e0271568a5b61d073b344c200c1ebf3490840930 --- .../intellij/openapi/util/text/PastParticipleTest.java | 3 ++- .../com/intellij/openapi/util/text/PastParticiple.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/util/text/PastParticipleTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/util/text/PastParticipleTest.java index 92384641c831..6531038a2457 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/util/text/PastParticipleTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/util/text/PastParticipleTest.java @@ -115,6 +115,7 @@ public class PastParticipleTest { assertEquals("matches", pastParticiple("matches")); assertEquals("equals", pastParticiple("equals")); assertEquals("of", pastParticiple("of")); - //assertEquals("running", generatePastParticiple("running")); + assertEquals("проблем", pastParticiple("проблем")); + assertEquals("string1", pastParticiple("string1")); } } \ No newline at end of file diff --git a/platform/util/src/com/intellij/openapi/util/text/PastParticiple.java b/platform/util/src/com/intellij/openapi/util/text/PastParticiple.java index bc9523828d71..ed7f6c9f7782 100644 --- a/platform/util/src/com/intellij/openapi/util/text/PastParticiple.java +++ b/platform/util/src/com/intellij/openapi/util/text/PastParticiple.java @@ -105,9 +105,16 @@ public class PastParticiple { char c1 = toLowerCase(verb.charAt(length - 1)); char c2 = toLowerCase(verb.charAt(length - 2)); if (c1 == 's' && (c2 == 'e' || c2 == 'l')) return true; + for (int i = 0; i < length; i++) { + if (!isAsciiLetter(verb.charAt(i))) return true; + } return false; } - + + private static boolean isAsciiLetter(char c) { + return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; + } + private static char toLowerCase(char c) { return (char)(c | 0x20); // cheap hack }