Skip to content

Commit

Permalink
Merge pull request #46 from santa112358/enable_full_width_space
Browse files Browse the repository at this point in the history
enable hashtag detection right before the full width space
  • Loading branch information
santa112358 committed Oct 29, 2020
2 parents b74ca09 + a908ff1 commit ab91932
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/decorator/decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
36 changes: 18 additions & 18 deletions lib/decorator/hashtag_regular_expression.dart
Original file line number Diff line number Diff line change
@@ -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,
);
6 changes: 6 additions & 0 deletions test/hashtagable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}

0 comments on commit ab91932

Please sign in to comment.