diff options
author | Roger Luo <rogerluo410@gmail.com> | 2022-06-09 19:15:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 14:15:08 +0300 |
commit | 2ae45cebbf2ec839bf2280765f958eb60d1f6374 (patch) | |
tree | 7e5a81f11ceebcbaf7c71cf9853a4c21fe28eeaf /web_src/js/utils.js | |
parent | 7948cb3149ab64484a8d4c6644f53f9f39accbef (diff) | |
download | gitea-2ae45cebbf2ec839bf2280765f958eb60d1f6374.tar.gz gitea-2ae45cebbf2ec839bf2280765f958eb60d1f6374.zip |
Feature: Find files in repo (#15028)
* Create finding files page ui in repo page
* Get tree entries for find repo files.
* Move find files JS to individual file.
* gen swagger.
* Add enry.IsVendor to exclude entries
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'web_src/js/utils.js')
-rw-r--r-- | web_src/js/utils.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 86a64b8b75..67f8f1cc98 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -58,3 +58,35 @@ export function parseIssueHref(href) { const [_, owner, repo, type, index] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || []; return {owner, repo, type, index}; } + +// return the sub-match result as an array: [unmatched, matched, unmatched, matched, ...] +// res[even] is unmatched, res[odd] is matched, see unit tests for examples +export function strSubMatch(full, sub) { + const res = ['']; + let i = 0, j = 0; + for (; i < sub.length && j < full.length;) { + while (j < full.length) { + if (sub[i] === full[j]) { + if (res.length % 2 !== 0) res.push(''); + res[res.length - 1] += full[j]; + j++; + i++; + } else { + if (res.length % 2 === 0) res.push(''); + res[res.length - 1] += full[j]; + j++; + break; + } + } + } + if (i !== sub.length) { + // if the sub string doesn't match the full, only return the full as unmatched. + return [full]; + } + if (j < full.length) { + // append remaining chars from full to result as unmatched + if (res.length % 2 === 0) res.push(''); + res[res.length - 1] += full.substring(j); + } + return res; +} |