Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable hashtag detection right before the full width space #46

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}