From a908ff1a6d8bf6b2de4654af3b7641f4cc3efa16 Mon Sep 17 00:00:00 2001 From: santa112358 Date: Thu, 29 Oct 2020 18:57:05 +0900 Subject: [PATCH] enable hashtag detection right before the full width space --- lib/decorator/decorator.dart | 2 +- lib/decorator/hashtag_regular_expression.dart | 36 +++++++++---------- test/hashtagable_test.dart | 6 ++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/decorator/decorator.dart b/lib/decorator/decorator.dart index b4a9e76..b1e86c6 100644 --- a/lib/decorator/decorator.dart +++ b/lib/decorator/decorator.dart @@ -104,7 +104,7 @@ class Decorator { final fullWidthRegExpMatches = fullWidthRegExp.allMatches(copiedText).toList(); final tokenRegExp = - RegExp(r'[・ぁ-んーァ-ヶ一-龥\u1100-\u11FF\uAC00-\uD7A30-9a-zA-Z]'); + RegExp(r'[・ぁ-んーァ-ヶ一-龥\u1100-\u11FF\uAC00-\uD7A30-9a-zA-Z ]'); final emojiMatches = fullWidthRegExpMatches .where((match) => (!tokenRegExp .hasMatch(copiedText.substring(match.start, match.end)))) diff --git a/lib/decorator/hashtag_regular_expression.dart b/lib/decorator/hashtag_regular_expression.dart index d4e5a4b..7f09fc4 100644 --- a/lib/decorator/hashtag_regular_expression.dart +++ b/lib/decorator/hashtag_regular_expression.dart @@ -1,38 +1,38 @@ -const _Symbols = '·・ー_'; +const _symbols = '·・ー_'; -const _Numbers = '0-90-9'; +const _numbers = '0-90-9'; -const _EnglishLetters = 'a-zA-Za-zA-Z'; +const _englishLetters = 'a-zA-Za-zA-Z'; -const _JapaneseLetters = 'ぁ-んァ-ン一-龠'; +const _japaneseLetters = 'ぁ-んァ-ン一-龠'; -const _KoreanLetters = '\u1100-\u11FF\uAC00-\uD7A3'; +const _koreanLetters = '\u1100-\u11FF\uAC00-\uD7A3'; -const _SpanishLetters = 'áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ'; +const _spanishLetters = 'áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ'; -const _ArabicLetters = '\u0621-\u064A'; +const _arabicLetters = '\u0621-\u064A'; -const _ThaiLetters = '\u0E00-\u0E7F'; +const _thaiLetters = '\u0E00-\u0E7F'; -const _HashTagContentLetters = _Symbols + - _Numbers + - _EnglishLetters + - _JapaneseLetters + - _KoreanLetters + - _SpanishLetters + - _ArabicLetters + - _ThaiLetters; +const hashTagContentLetters = _symbols + + _numbers + + _englishLetters + + _japaneseLetters + + _koreanLetters + + _spanishLetters + + _arabicLetters + + _thaiLetters; /// Regular expression to extract hashtag from text /// /// Supports English, Japanese, Korean, Spanish, Arabic, and Thai final hashTagRegExp = RegExp( - "(?!\\n)(?:^|\\s)(#([$_HashTagContentLetters]+))", + "(?!\\n)(?:^|\\s)(#([$hashTagContentLetters]+))", multiLine: true, ); /// Regular expression when you select decorateAtSign final hashTagAtSignRegExp = RegExp( - "(?!\\n)(?:^|\\s)([#@]([$_HashTagContentLetters]+))", + "(?!\\n)(?:^|\\s)([#@]([$hashTagContentLetters]+))", multiLine: true, ); diff --git a/test/hashtagable_test.dart b/test/hashtagable_test.dart index 248eeb2..85d14db 100644 --- a/test/hashtagable_test.dart +++ b/test/hashtagable_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hashtagable/decorator/decorator.dart'; import 'package:hashtagable/functions.dart'; +import 'package:hashtagable/hashtagable.dart'; void main() { final decoratedColor = Colors.red; @@ -128,4 +129,9 @@ void main() { expect(hashTagList[2], "#So"); expect(hashTagList.length, 3); }); + + test("detect hashtag before the full width space", () { + final source = "The space right before the hashtag is #fullWidth"; + expect(hasHashTags(source), true); + }); }