exec regex

This commit is contained in:
j 2011-07-23 15:44:11 +02:00
parent 8906cecd3e
commit 23adaa05df
3 changed files with 12 additions and 13 deletions

View file

@ -473,17 +473,17 @@ Ox.Input = function(options, self) {
} else if (value == '.') {
value = '0.' + self.decimals;
cursor = [2, value.length];
} else if (!/\./(value)) {
value += '.' + self.decimals
} else if (!/\./.test(value)) {
value += '.' + self.decimals;
cursor = [value.indexOf('.'), value.length];
} else if (/^\./(value)) {
} else if (/^\./.test(value)) {
value = '0' + value;
cursor = [2, value.length];
} else if (/\.$/(value)) {
} else if (/\.$/.test(value)) {
//Ox.print('$$$$$$$$$$$')
value += self.decimals;
cursor = [value.indexOf('.') + 1, value.length];
} else if (/\./(value) && self.options.decimals) {
} else if (/\./.test(value) && self.options.decimals) {
length = value.split('.')[1].length;
if (length > self.options.decimals) {
value = value.substr(0, value.indexOf('.') + 1 + self.options.decimals);
@ -499,7 +499,7 @@ Ox.Input = function(options, self) {
cursor = [0, 1];
}
}
while (/^0\d/(value)) {
while (/^0\d/.test(value)) {
value = value.substr(1, value.length);
}
if (!regexp.test(value) || value < self.options.min || value > self.options.max) {

View file

@ -1013,7 +1013,6 @@ Ox.Map = function(options, self) {
if (place) {
select();
} else {
Ox.print()
// async && place doesn't exist yet
self.options.places({
keys: self.placeKeys,

View file

@ -206,7 +206,7 @@ Ox.sort = function(arr, fn) {
values = fn ? arr.map(fn) : arr;
// find leading numbers
values.forEach(function(val, i) {
var match = /^\d+/(val);
var match = /^\d+/.exec(val);
matches[val] = match ? match[0] : '';
});
// get length of longest leading number
@ -1462,7 +1462,7 @@ Ox.parseDate <f> Takes a string ('YYYY-MM-DD HH:MM:SS') and returns a date
Ox.parseDate = function(str, utc) {
var date = new Date(0),
defaults = [, 1, 1, 0, 0, 0],
values = /(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/(str);
values = /(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/.exec(str);
values.shift();
values = values.map(function(v, i) {
return v || defaults[i];
@ -1486,7 +1486,7 @@ Ox.parseDateRange = function(start, end, utc) {
'FullYear', 'Month', 'Date', 'Hours', 'Minutes', 'Seconds'
][
Ox.compact(
/(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/(end)
/(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/.exec(end)
).length - 2
];
Ox['set' + part](dates[1], Ox['get' + part](dates[1], utc) + 1, utc);
@ -2320,7 +2320,7 @@ Ox.formatDateRange = function(start, end, utc) {
}),
parts = range.map(function(str) {
var parts = Ox.compact(
/(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/(str)
/(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?/.exec(str)
);
parts.shift();
return parts.map(function(part) {
@ -4151,7 +4151,7 @@ Ox.parsePath <f> Returns the components of a path
{extension: '', filename: '.foo', pathname: ''}
@*/
Ox.parsePath = function(str) {
var matches = /^(.+\/)?(.+?(\..+)?)?$/(str);
var matches = /^(.+\/)?(.+?(\..+)?)?$/.exec(str);
return {
pathname: matches[1] || '',
filename: matches[2] || '',
@ -4400,7 +4400,7 @@ Ox.words = function(str) {
var arr = str.toLowerCase().split(/\b/),
chr = "-'",
len = arr.length,
startsWithWord = !!/\w/(arr[0]);
startsWithWord = /\w/.test(arr[0]);
arr.forEach(function(v, i) {
// find single occurrences of "-" or "-"
// that are not at the beginning or end of the string