From f742333369bdfd385b7041ade0d77e94ed67a4fb Mon Sep 17 00:00:00 2001 From: Coachonko Date: Thu, 15 Jun 2023 17:15:04 +0200 Subject: [PATCH] More documentation --- slugify.v | 2 +- slugify_test.v | 4 +-- substitutions.v | 77 +++++++++++++++++++++++++------------------------ 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/slugify.v b/slugify.v index 90e59ba..db0fef5 100644 --- a/slugify.v +++ b/slugify.v @@ -3,7 +3,7 @@ module slugify import regex pub struct SlugifyOptions { - mut: +mut: // to_lower when true produces lowercase slugs. to_lower bool // max_length is the maximum number of characters allowed in the slug. diff --git a/slugify_test.v b/slugify_test.v index 67c643d..21c28c2 100644 --- a/slugify_test.v +++ b/slugify_test.v @@ -11,7 +11,7 @@ fn test_slugify_make_lang() { slugifier.lang = Language.no assert slugifier.make('Har du røykt sokka dine?') == 'har-du-roeykt-sokka-dine' slugifier.lang = Language.it - assert slugifier.make('Un € o un $') == "un-euro-o-un-dollaro" + assert slugifier.make('Un € o un $') == 'un-eur-o-un' } fn test_max_length() { @@ -29,7 +29,7 @@ fn test_smart_truncate() { assert slugifier.make('Sugma Willy: we are your fitness family.') == 'Sugma-Willy' } -fn test_skip_transliteration(){ +fn test_skip_transliteration() { mut slugifier := SlugifyOptions{ transliterate: false } diff --git a/substitutions.v b/substitutions.v index faf5f0c..16c6da0 100644 --- a/substitutions.v +++ b/substitutions.v @@ -23,6 +23,12 @@ const ( // When passing a different language to `make_lang`, any mapping found in the passed language will // override the mappings in `en_sub`. Mappings that exist in `en_sub` but not in the passed language // will still apply. + // + // Please note that some symbols are not only used for a single meaning. For example `£` is not only + // used for british pounds. In such cases it is best to use either more ambiguous replacement than + // `GBP` or none at all and let the character be removed. + // + // Replacements should only contain `\w` characters and hyphens `-`, any other character will be removed. en_sub = { '&': 'and' '@': 'at' @@ -30,48 +36,44 @@ const ( '<': 'less' '>': 'greater' '|': 'or' - // TODO some currency symbols are used for more than just one currency. - '€': 'euro' - '$': 'dollar' - '¢': 'cent' - '£': 'pound' - '¤': 'currency' - '¥': 'yen' - '฿': 'baht' - '₠': 'ecu' - '₢': 'cruzeiro' - '₣': 'french franc' - '₤': 'lira' - '₥': 'mill' - '₦': 'naira' - '₧': 'peseta' - '₨': 'rupee' - '₩': 'won' - '₪': 'new shequel' - '₫': 'dong' - '₭': 'kip' - '₮': 'tugrik' - '₯': 'drachma' - '₰': 'penny' - '₱': 'peso' - '₲': 'guarani' - '₳': 'austral' - '₴': 'hryvnia' - '₵': 'cedi' - '₸': 'kazakhstani tenge' - '₹': 'indian rupee' - '₺': 'turkish lira' - '₽': 'russian ruble' - '₿': 'bitcoin' - '؋': 'afghani' - '﷼': 'rial' - // + '€': 'EUR' + '¢': 'C' + '£': 'PS' + '¥': 'Y' + '฿': 'Bh' + '₠': 'ECU' + '₢': 'Cr' + '₣': 'FF' + '₤': 'L' + '₥': 'mil' + '₦': 'N' + '₧': 'Pts' + '₨': 'Rs' + '₩': 'W' + '₪': 'NS' + '₫': 'D' + '₭': 'K' + '₮': 'T' + '₯': 'Dr' + '₰': 'Pf' + '₱': 'P' + '₲': 'G' + '₳': 'A' + '₴': 'UAH' + '₵': 'C' + '₸': 'T' + '₹': 'Rs' + '₺': 'L' + '₽': 'R' + '₿': 'BTC' '∆': 'delta' '∑': 'sum' '∞': 'infinity' - '♥': 'love' + '♥': 'heart' } fa_sub = { + 'ک': 'kh' + 'ی': 'y' } it_sub = { '&': 'e' @@ -80,7 +82,6 @@ const ( '<': 'minore' '>': 'maggiore' '|': 'o' - '$': 'dollaro' } nl_sub = { '&': 'en'