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8E;YAC9E,8EAA8E;YAC9E,wDAAwD;YACxD,IAAI,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAE,QAAQ,CAAE,EAAG;gBACvD,IAAI,WAAW,GAAG,KAAK,CAAE,CAAC,CAAE,EACxB,OAAO,GAAG,KAAK,CAAE,CAAC,CAAE,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC,CAAE,+CAA+C;gBAErF,OAAO,CAAC,IAAI,CAAE,IAAI,4BAAY,CAAE;oBAC/B,UAAU,EAAI,UAAU;oBACxB,WAAW,EAAG,WAAW;oBACzB,MAAM,EAAQ,MAAM;oBACpB,WAAW,EAAG,WAAW;oBACzB,OAAO,EAAO,OAAO;iBACrB,CAAE,CAAE,CAAC;aACN;SACD;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IAEF,qBAAC;AAAD,CA/EA,AA+EC,CA/EmC,iBAAO,GA+E1C;AA/EY,wCAAc","file":"hashtag-matcher.js","sourcesContent":["import { Matcher, MatcherConfig } from \"./matcher\";\nimport { HashtagServices } from \"../autolinker\";\nimport { alphaNumericAndMarksCharsStr } from \"../regex-lib\";\nimport { HashtagMatch } from \"../match/hashtag-match\";\nimport { Match } from \"../match/match\";\n\n// RegExp objects which are shared by all instances of HashtagMatcher. These are\n// here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is\n// called multiple times, thus instantiating HashtagMatcher and its RegExp \n// objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). \n// See descriptions of the properties where they are used for details about them\nconst matcherRegex = new RegExp( `#[_${alphaNumericAndMarksCharsStr}]{1,139}(?![_${alphaNumericAndMarksCharsStr}])`, 'g' ); // lookahead used to make sure we don't match something above 139 characters\nconst nonWordCharRegex = new RegExp( '[^' + alphaNumericAndMarksCharsStr + ']' );\n\n/**\n * @class Autolinker.matcher.Hashtag\n * @extends Autolinker.matcher.Matcher\n *\n * Matcher to find HashtagMatch matches in an input string.\n */\nexport class HashtagMatcher extends Matcher {\n\n\t/**\n\t * @cfg {String} serviceName\n\t *\n\t * The service to point hashtag matches to. See {@link Autolinker#hashtag}\n\t * for available values.\n\t */\n\tprotected readonly serviceName: HashtagServices = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * The regular expression to match Hashtags. Example match:\n\t *\n\t * #asdf\n\t *\n\t * @protected\n\t * @property {RegExp} matcherRegex\n\t */\n\tprotected matcherRegex = matcherRegex;\n\n\t/**\n\t * The regular expression to use to check the character before a username match to\n\t * make sure we didn't accidentally match an email address.\n\t *\n\t * For example, the string \"asdf@asdf.com\" should not match \"@asdf\" as a username.\n\t *\n\t * @protected\n\t * @property {RegExp} nonWordCharRegex\n\t */\n\tprotected nonWordCharRegex = nonWordCharRegex;\n\n\n\t/**\n\t * @method constructor\n\t * @param {Object} cfg The configuration properties for the Match instance,\n\t * specified in an Object (map).\n\t */\n\tconstructor( cfg: HashtagMatcherConfig ) {\n\t\tsuper( cfg );\n\n\t\tthis.serviceName = cfg.serviceName;\n\t}\n\n\n\t/**\n\t * @inheritdoc\n\t */\n\tparseMatches( text: string ) {\n\t\tlet matcherRegex = this.matcherRegex,\n\t\t nonWordCharRegex = this.nonWordCharRegex,\n\t\t serviceName = this.serviceName,\n\t\t tagBuilder = this.tagBuilder,\n\t\t matches: Match[] = [],\n\t\t match: RegExpExecArray | null;\n\n\t\twhile( ( match = matcherRegex.exec( text ) ) !== null ) {\n\t\t\tlet offset = match.index,\n\t\t\t prevChar = text.charAt( offset - 1 );\n\n\t\t\t// If we found the match at the beginning of the string, or we found the match\n\t\t\t// and there is a whitespace char in front of it (meaning it is not a '#' char\n\t\t\t// in the middle of a word), then it is a hashtag match.\n\t\t\tif( offset === 0 || nonWordCharRegex.test( prevChar ) ) {\n\t\t\t\tlet matchedText = match[ 0 ],\n\t\t\t\t hashtag = match[ 0 ].slice( 1 ); // strip off the '#' character at the beginning\n\n\t\t\t\tmatches.push( new HashtagMatch( {\n\t\t\t\t\ttagBuilder : tagBuilder,\n\t\t\t\t\tmatchedText : matchedText,\n\t\t\t\t\toffset : offset,\n\t\t\t\t\tserviceName : serviceName,\n\t\t\t\t\thashtag : hashtag\n\t\t\t\t} ) );\n\t\t\t}\n\t\t}\n\n\t\treturn matches;\n\t}\n\n}\n\nexport interface HashtagMatcherConfig extends MatcherConfig {\n\tserviceName: HashtagServices\n}"]}
\No newline at end of file