/** * StringMapper.js * * Released under LGPL License. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ import UnicodeData from './UnicodeData'; import Arr from '../alien/Arr'; const SETS = UnicodeData.SETS; const OTHER = UnicodeData.characterIndices.OTHER; const getType = function (char) { let j, set, type = OTHER; const setsLength = SETS.length; for (j = 0; j < setsLength; ++j) { set = SETS[j]; if (set && set.test(char)) { type = j; break; } } return type; }; const memoize = function (func) { const cache = {}; return function (char) { if (cache[char]) { return cache[char]; } else { const result = func(char); cache[char] = result; return result; } }; }; const classify = function (string) { const memoized = memoize(getType); return Arr.map(string.split(''), memoized); }; export default { classify };