From d4c099de8c597255f8c83707625615fd8b8509aa Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 28 Oct 2014 14:46:09 -0700 Subject: [PATCH] feat(facade/lang): add math and regexp support --- modules/facade/src/lang.dart | 27 ++++++++++++++++++++++++++- modules/facade/src/lang.es6 | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/facade/src/lang.dart b/modules/facade/src/lang.dart index 24843950e2..1e5e83383e 100644 --- a/modules/facade/src/lang.dart +++ b/modules/facade/src/lang.dart @@ -1,6 +1,13 @@ library angular.core.facade.lang; -export 'dart:core' show Type; +export 'dart:core' show Type, RegExp; +import 'dart:math' as math; + +class Math { + static final _random = new math.Random(); + static int floor(num n) => n.floor(); + static double random() => _random.nextDouble(); +} class FIELD { final String definition; @@ -58,3 +65,21 @@ class NumberWrapper { } } +class RegExpWrapper { + static RegExp create(regExpStr) { + return new RegExp(regExpStr); + } + static matcher(regExp, input) { + return regExp.allMatches(input).iterator; + } +} + +class RegExpMatcherWrapper { + static next(matcher) { + if (matcher.moveNext()) { + return matcher.current; + } + return null; + } +} + diff --git a/modules/facade/src/lang.es6 b/modules/facade/src/lang.es6 index 7d9310e62f..f7a6b43803 100644 --- a/modules/facade/src/lang.es6 +++ b/modules/facade/src/lang.es6 @@ -1,4 +1,5 @@ export var Type = Function; +export var Math = window.Math; export class FIELD { constructor(definition) { @@ -107,3 +108,24 @@ export function int() {}; int.assert = function(value) { return value == null || typeof value == 'number' && value === Math.floor(value); } + +export var RegExp = window.RegExp; + +export class RegExpWrapper { + static create(regExpStr):RegExp { + return new RegExp(regExpStr, 'g'); + } + static matcher(regExp, input) { + return { + re: regExp, + input: input + }; + } +} + +export class RegExpMatcherWrapper { + static next(matcher) { + return matcher.re.exec(matcher.input); + } +} +