Javascript 如何将JS移植到AS3?
我想使用AS3中的函数。 要在AS3中使用JavaScript,我需要在JavaScript中更改什么?是否有类似转换器的东西,因为两种语言似乎非常相似Javascript 如何将JS移植到AS3?,javascript,actionscript-3,porting,Javascript,Actionscript 3,Porting,我想使用AS3中的函数。 要在AS3中使用JavaScript,我需要在JavaScript中更改什么?是否有类似转换器的东西,因为两种语言似乎非常相似 twttr.txt.regexen.urlHasHttps = /^https:\/\//i; // Returns the length of Tweet text with consideration to t.co URL replacement // and chars outside the basic mul
twttr.txt.regexen.urlHasHttps = /^https:\/\//i;
// Returns the length of Tweet text with consideration to t.co URL replacement
// and chars outside the basic multilingual plane that use 2 UTF16 code points
twttr.txt.getTweetLength = function(text, options) {
if (!options) {
options = {
// These come from https://api.twitter.com/1/help/configuration.json
// described by https://dev.twitter.com/docs/api/1/get/help/configuration
short_url_length: 22,
short_url_length_https: 23
};
}
var textLength = twttr.txt.getUnicodeTextLength(text),
urlsWithIndices = twttr.txt.extractUrlsWithIndices(text);
twttr.txt.modifyIndicesFromUTF16ToUnicode(text, urlsWithIndices);
for (var i = 0; i < urlsWithIndices.length; i++) {
// Subtract the length of the original URL
textLength += urlsWithIndices[i].indices[0] - urlsWithIndices[i].indices[1];
// Add 23 characters for URL starting with https://
// Otherwise add 22 characters
if (urlsWithIndices[i].url.toLowerCase().match(twttr.txt.regexen.urlHasHttps)) {
textLength += options.short_url_length_https;
} else {
textLength += options.short_url_length;
}
}
return textLength;
};
twttr.txt.getUnicodeTextLength = function(text) {
return text.replace(twttr.txt.regexen.non_bmp_code_pairs, ' ').length;
};
twttr.txt.extractUrlsWithIndices = function(text, options) {
if (!options) {
options = {extractUrlsWithoutProtocol: true};
}
if (!text || (options.extractUrlsWithoutProtocol ? !text.match(/\./) : !text.match(/:/))) {
return [];
}
var urls = [];
while (twttr.txt.regexen.extractUrl.exec(text)) {
var before = RegExp.$2, url = RegExp.$3, protocol = RegExp.$4, domain = RegExp.$5, path = RegExp.$7;
var endPosition = twttr.txt.regexen.extractUrl.lastIndex,
startPosition = endPosition - url.length;
// if protocol is missing and domain contains non-ASCII characters,
// extract ASCII-only domains.
if (!protocol) {
if (!options.extractUrlsWithoutProtocol
|| before.match(twttr.txt.regexen.invalidUrlWithoutProtocolPrecedingChars)) {
continue;
}
var lastUrl = null,
asciiEndPosition = 0;
domain.replace(twttr.txt.regexen.validAsciiDomain, function(asciiDomain) {
var asciiStartPosition = domain.indexOf(asciiDomain, asciiEndPosition);
asciiEndPosition = asciiStartPosition + asciiDomain.length;
lastUrl = {
url: asciiDomain,
indices: [startPosition + asciiStartPosition, startPosition + asciiEndPosition]
};
if (path
|| asciiDomain.match(twttr.txt.regexen.validSpecialShortDomain)
|| !asciiDomain.match(twttr.txt.regexen.invalidShortDomain)) {
urls.push(lastUrl);
}
});
// no ASCII-only domain found. Skip the entire URL.
if (lastUrl == null) {
continue;
}
// lastUrl only contains domain. Need to add path and query if they exist.
if (path) {
lastUrl.url = url.replace(domain, lastUrl.url);
lastUrl.indices[1] = endPosition;
}
} else {
// In the case of t.co URLs, don't allow additional path characters.
if (url.match(twttr.txt.regexen.validTcoUrl)) {
url = RegExp.lastMatch;
endPosition = startPosition + url.length;
}
urls.push({
url: url,
indices: [startPosition, endPosition]
});
}
}
return urls;
};
twttr.txt.modifyIndicesFromUTF16ToUnicode = function(text, entities) {
twttr.txt.convertUnicodeIndices(text, entities, true);
};
twttr.txt.regexen.urlHasHttps=/^https:\/\///i;
//返回Tweet文本的长度,并考虑t.co URL替换
//和使用2个UTF16代码点的基本多语言平面之外的字符
twttr.txt.getTweetLength=函数(文本,选项){
如果(!选项){
选项={
//这些是从哪里来的https://api.twitter.com/1/help/configuration.json
//描述https://dev.twitter.com/docs/api/1/get/help/configuration
短url长:22,
短地址长度https:23
};
}
var textLength=twttr.txt.getUnicodeTextLength(文本),
urlsWithIndices=twttr.txt.extractUrlsWithIndices(文本);
twttr.txt.modifyIndicates fromUTF16Tounicode(文本,URLSwithindicates);
对于(变量i=0;i
问候语!Stack overflow不是一种代码转换服务,在这里,要求链接到转换器和教程等内容的问题被认为是离题的。以下是我的建议:做一些研究,尝试一些事情。然后,如果您对代码的某些特定部分不起作用有问题,可以问一个关于这一点的精确问题。它们类似,但您仍然无法自动将一个转换为另一个,必须手动完成。