From 253e37fa2d531afb9e8fd706d735bc178a8032cb Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sun, 24 Jan 2021 17:48:25 +0000 Subject: ignore trailing spaces when creating text index entries git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1361 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 5 +++ .../jackcess/impl/General97IndexCodes.java | 10 ++---- .../jackcess/impl/GeneralLegacyIndexCodes.java | 36 +++++++++++++++++----- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bac4092..7fbba3e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,11 @@ Tim McCune + + + Ignore trailing spaces when creating text index entries. + + Add Automatic-Module-Name in order to make Jackcess safe to use in the diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/General97IndexCodes.java b/src/main/java/com/healthmarketscience/jackcess/impl/General97IndexCodes.java index 6b68aea..77ebb67 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/General97IndexCodes.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/General97IndexCodes.java @@ -99,14 +99,8 @@ public class General97IndexCodes extends GeneralLegacyIndexCodes Object value, ByteStream bout, boolean isAscending) throws IOException { - // first, convert to string - String str = ColumnImpl.toCharSequence(value).toString(); - - // all text columns (including memos) are only indexed up to the max - // number of chars in a VARCHAR column - if(str.length() > MAX_TEXT_INDEX_CHAR_LENGTH) { - str = str.substring(0, MAX_TEXT_INDEX_CHAR_LENGTH); - } + // convert to string + String str = toIndexCharSequence(value); // record previous entry length so we can do any post-processing // necessary for this entry (handling descending) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/GeneralLegacyIndexCodes.java b/src/main/java/com/healthmarketscience/jackcess/impl/GeneralLegacyIndexCodes.java index d8d763d..0d151e0 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/GeneralLegacyIndexCodes.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/GeneralLegacyIndexCodes.java @@ -511,14 +511,8 @@ public class GeneralLegacyIndexCodes { Object value, ByteStream bout, boolean isAscending) throws IOException { - // first, convert to string - String str = ColumnImpl.toCharSequence(value).toString(); - - // all text columns (including memos) are only indexed up to the max - // number of chars in a VARCHAR column - if(str.length() > MAX_TEXT_INDEX_CHAR_LENGTH) { - str = str.substring(0, MAX_TEXT_INDEX_CHAR_LENGTH); - } + // convert to string + String str = toIndexCharSequence(value); // record previous entry length so we can do any post-processing // necessary for this entry (handling descending) @@ -641,6 +635,32 @@ public class GeneralLegacyIndexCodes { bout.write(END_EXTRA_TEXT); } + protected static String toIndexCharSequence(Object value) + throws IOException { + + // first, convert to string + String str = ColumnImpl.toCharSequence(value).toString(); + + // all text columns (including memos) are only indexed up to the max + // number of chars in a VARCHAR column + int len = str.length(); + if(len > MAX_TEXT_INDEX_CHAR_LENGTH) { + str = str.substring(0, MAX_TEXT_INDEX_CHAR_LENGTH); + len = MAX_TEXT_INDEX_CHAR_LENGTH; + } + + // trailing spaces are ignored for text index entries + if((len > 0) && (str.charAt(len - 1) == ' ')) { + do { + --len; + } while((len > 0) && (str.charAt(len - 1) == ' ')); + + str = str.substring(0, len); + } + + return str; + } + /** * Encodes the given extra code info in the given stream. */ -- cgit v1.2.3