📄 scriptresource(2).axd
字号:
String.localeFormat = function String$localeFormat(format, args) {
/// <summary locid="M:J#String.localeFormat" />
/// <param name="format" type="String"></param>
/// <param name="args" parameterArray="true" mayBeNull="true"></param>
/// <returns type="String"></returns>
var e = Function._validateParams(arguments, [
{name: "format", type: String},
{name: "args", mayBeNull: true, parameterArray: true}
]);
if (e) throw e;
return String._toFormattedString(true, arguments);
}
String._toFormattedString = function String$_toFormattedString(useLocale, args) {
var result = '';
var format = args[0];
for (var i=0;;) {
// Find the next opening or closing brace
var open = format.indexOf('{', i);
var close = format.indexOf('}', i);
if ((open < 0) && (close < 0)) {
// Not found: copy the end of the string and break
result += format.slice(i);
break;
}
if ((close > 0) && ((close < open) || (open < 0))) {
// Closing brace before opening is an error
if (format.charAt(close + 1) !== '}') {
throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
}
result += format.slice(i, close + 1);
i = close + 2;
continue;
}
// Copy the string before the brace
result += format.slice(i, open);
i = open + 1;
// Check for double braces (which display as one and are not arguments)
if (format.charAt(i) === '{') {
result += '{';
i++;
continue;
}
// at this point we have a valid opening brace, which should be matched by a closing brace.
if (close < 0) throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
// Find the closing brace
// Get the string between the braces, and split it around the ':' (if any)
var brace = format.substring(i, close);
var colonIndex = brace.indexOf(':');
var argNumber = parseInt((colonIndex < 0)? brace : brace.substring(0, colonIndex), 10) + 1;
if (isNaN(argNumber)) throw Error.argument('format', Sys.Res.stringFormatInvalid);
var argFormat = (colonIndex < 0)? '' : brace.substring(colonIndex + 1);
var arg = args[argNumber];
if (typeof(arg) === "undefined" || arg === null) {
arg = '';
}
// If it has a toFormattedString method, call it. Otherwise, call toString()
if (arg.toFormattedString) {
result += arg.toFormattedString(argFormat);
}
else if (useLocale && arg.localeFormat) {
result += arg.localeFormat(argFormat);
}
else if (arg.format) {
result += arg.format(argFormat);
}
else
result += arg.toString();
i = close + 1;
}
return result;
}
Boolean.__typeName = 'Boolean';
Boolean.__class = true;
Boolean.parse = function Boolean$parse(value) {
/// <summary locid="M:J#Boolean.parse" />
/// <param name="value" type="String"></param>
/// <returns type="Boolean"></returns>
var e = Function._validateParams(arguments, [
{name: "value", type: String}
]);
if (e) throw e;
var v = value.trim().toLowerCase();
if (v === 'false') return false;
if (v === 'true') return true;
throw Error.argumentOutOfRange('value', value, Sys.Res.boolTrueOrFalse);
}
Date.__typeName = 'Date';
Date.__class = true;
Date._appendPreOrPostMatch = function Date$_appendPreOrPostMatch(preMatch, strBuilder) {
// appends pre- and post- token match strings while removing escaped characters.
// Returns a single quote count which is used to determine if the token occurs
// in a string literal.
var quoteCount = 0;
var escaped = false;
for (var i = 0, il = preMatch.length; i < il; i++) {
var c = preMatch.charAt(i);
switch (c) {
case '\'':
if (escaped) strBuilder.append("'");
else quoteCount++;
escaped = false;
break;
case '\\':
if (escaped) strBuilder.append("\\");
escaped = !escaped;
break;
default:
strBuilder.append(c);
escaped = false;
break;
}
}
return quoteCount;
}
Date._expandFormat = function Date$_expandFormat(dtf, format) {
// expands unspecified or single character date formats into the full pattern.
if (!format) {
format = "F";
}
if (format.length === 1) {
switch (format) {
case "d":
return dtf.ShortDatePattern;
case "D":
return dtf.LongDatePattern;
case "t":
return dtf.ShortTimePattern;
case "T":
return dtf.LongTimePattern;
case "F":
return dtf.FullDateTimePattern;
case "M": case "m":
return dtf.MonthDayPattern;
case "s":
return dtf.SortableDateTimePattern;
case "Y": case "y":
return dtf.YearMonthPattern;
default:
throw Error.format(Sys.Res.formatInvalidString);
}
}
return format;
}
Date._expandYear = function Date$_expandYear(dtf, year) {
// expands 2-digit year into 4 digits.
if (year < 100) {
var curr = new Date().getFullYear();
year += curr - (curr % 100);
if (year > dtf.Calendar.TwoDigitYearMax) {
return year - 100;
}
}
return year;
}
Date._getParseRegExp = function Date$_getParseRegExp(dtf, format) {
// converts a format string into a regular expression with groups that
// can be used to extract date fields from a date string.
// check for a cached parse regex.
if (!dtf._parseRegExp) {
dtf._parseRegExp = {};
}
else if (dtf._parseRegExp[format]) {
return dtf._parseRegExp[format];
}
// expand single digit formats, then escape regular expression characters.
var expFormat = Date._expandFormat(dtf, format);
expFormat = expFormat.replace(/([\^\$\.\*\+\?\|\[\]\(\)\{\}])/g, "\\\\$1");
var regexp = new Sys.StringBuilder("^");
var groups = [];
var index = 0;
var quoteCount = 0;
var tokenRegExp = Date._getTokenRegExp();
var match;
// iterate through each date token found.
while ((match = tokenRegExp.exec(expFormat)) !== null) {
var preMatch = expFormat.slice(index, match.index);
index = tokenRegExp.lastIndex;
// don't replace any matches that occur inside a string literal.
quoteCount += Date._appendPreOrPostMatch(preMatch, regexp);
if ((quoteCount%2) === 1) {
regexp.append(match[0]);
continue;
}
// add a regex group for the token.
switch (match[0]) {
case 'dddd': case 'ddd':
case 'MMMM': case 'MMM':
regexp.append("(\\D+)");
break;
case 'tt': case 't':
regexp.append("(\\D*)");
break;
case 'yyyy':
regexp.append("(\\d{4})");
break;
case 'fff':
regexp.append("(\\d{3})");
break;
case 'ff':
regexp.append("(\\d{2})");
break;
case 'f':
regexp.append("(\\d)");
break;
case 'dd': case 'd':
case 'MM': case 'M':
case 'yy': case 'y':
case 'HH': case 'H':
case 'hh': case 'h':
case 'mm': case 'm':
case 'ss': case 's':
regexp.append("(\\d\\d?)");
break;
case 'zzz':
regexp.append("([+-]?\\d\\d?:\\d{2})");
break;
case 'zz': case 'z':
regexp.append("([+-]?\\d\\d?)");
break;
}
Array.add(groups, match[0]);
}
Date._appendPreOrPostMatch(expFormat.slice(index), regexp);
regexp.append("$");
// allow whitespace to differ when matching formats.
var regexpStr = regexp.toString().replace(/\s+/g, "\\s+");
var parseRegExp = {'regExp': regexpStr, 'groups': groups};
// cache the regex for this format.
dtf._parseRegExp[format] = parseRegExp;
return parseRegExp;
}
Date._getTokenRegExp = function Date$_getTokenRegExp() {
// regular expression for matching dateTime tokens in format strings.
return /dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z/g;
}
Date.parseLocale = function Date$parseLocale(value, formats) {
/// <summary locid="M:J#Date.parseLocale" />
/// <param name="value" type="String"></param>
/// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
/// <returns type="Date"></returns>
var e = Function._validateParams(arguments, [
{name: "value", type: String},
{name: "formats", mayBeNull: true, optional: true, parameterArray: true}
]);
if (e) throw e;
return Date._parse(value, Sys.CultureInfo.CurrentCulture, arguments);
}
Date.parseInvariant = function Date$parseInvariant(value, formats) {
/// <summary locid="M:J#Date.parseInvariant" />
/// <param name="value" type="String"></param>
/// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
/// <returns type="Date"></returns>
var e = Function._validateParams(arguments, [
{name: "value", type: String},
{name: "formats", mayBeNull: true, optional: true, parameterArray: true}
]);
if (e) throw e;
return Date._parse(value, Sys.CultureInfo.InvariantCulture, arguments);
}
Date._parse = function Date$_parse(value, cultureInfo, args) {
// args is a params array with value as the first item, followed by custom formats.
// try parse with custom formats.
var custom = false;
for (var i = 1, il = args.length; i < il; i++) {
var format = args[i];
if (format) {
custom = true;
var date = Date._parseExact(value, format, cultureInfo);
if (date) return date;
}
}
// try parse with culture formats.
if (! custom) {
var formats = cultureInfo._getDateTimeFormats();
for (var i = 0, il = formats.length; i < il; i++) {
var date = Date._parseExact(value, formats[i], cultureInfo);
if (date) return date;
}
}
return null;
}
Date._parseExact = function Date$_parseExact(value, format, cultureInfo) {
// try to parse the date string value by matching against the format string
// while using the specified culture for date field names.
value = value.trim();
var dtf = cultureInfo.dateTimeFormat;
// convert date formats into regular expressions with groupings.
// use the regexp to determine the input format and extract the date fields.
var parseInfo = Date._getParseRegExp(dtf, format);
var match = new RegExp(parseInfo.regExp).exec(value);
// DevDiv 124696: Return null to avoid Firefox warning "does not always return a value"
if (match === null) return null;
// found a date format that matches the input.
var groups = parseInfo.groups;
var year = null, month = null, date = null, weekDay = null;
var hour = 0, min = 0, sec = 0, msec = 0, tzMinOffset = null;
var pmHour = false;
// iterate the format groups to extract and set the date fields.
for (var j = 0, jl = groups.length; j < jl; j++) {
var matchGroup = match[j+1];
if (matchGroup) {
switch (groups[j]) {
case 'dd': case 'd':
// Day of month.
date = parseInt(matchGroup, 10);
// check that date is generally in valid range, also checking overflow below.
if ((date < 1) || (date > 31)) return null;
break;
case 'MMMM':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -