Files
react-native-devtools-frontend/node_modules/remark-stringify/lib/util/copy-identifier-encoding.js
T
Mathias Bynens 79e2cf0633 Add stylelint dependency
This also adds CC-BY-4.0 to the list of accepted licenses.

DISABLE_THIRD_PARTY_CHECK=update dependencies

Bug: chromium:1083142
Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
2020-06-11 06:20:04 +00:00

68 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict'
var entityPrefixLength = require('./entity-prefix-length')
module.exports = copy
var ampersand = '&'
var punctuationExppresion = /[-!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~_]/
// For shortcut and collapsed reference links, the contents is also an
// identifier, so we need to restore the original encoding and escaping
// that were present in the source string.
//
// This function takes the unescaped & unencoded value from shortcut’s
// child nodes and the identifier and encodes the former according to
// the latter.
function copy(value, identifier) {
var length = value.length
var count = identifier.length
var result = []
var position = 0
var index = 0
var start
while (index < length) {
// Take next non-punctuation characters from `value`.
start = index
while (index < length && !punctuationExppresion.test(value.charAt(index))) {
index += 1
}
result.push(value.slice(start, index))
// Advance `position` to the next punctuation character.
while (
position < count &&
!punctuationExppresion.test(identifier.charAt(position))
) {
position += 1
}
// Take next punctuation characters from `identifier`.
start = position
while (
position < count &&
punctuationExppresion.test(identifier.charAt(position))
) {
if (identifier.charAt(position) === ampersand) {
position += entityPrefixLength(identifier.slice(position))
}
position += 1
}
result.push(identifier.slice(start, position))
// Advance `index` to the next non-punctuation character.
while (index < length && punctuationExppresion.test(value.charAt(index))) {
index += 1
}
}
return result.join('')
}