//
//  TextUtils.m
//  AntsContract
//
//  Created by Ray on 12/20/16.
//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
//

#import "TextUtils.h"

@implementation TextUtils
+(NSArray*) expression_varable:(NSString*)content regex:(NSString*) pattern
{
    
    if(content==nil)
        return nil;
    
    
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:nil error:nil];
    
    NSArray *matches = [regex matchesInString:content options:nil range:NSMakeRange(0, content.length)];
    
    if (matches) {
        for (NSTextCheckingResult *match in matches) {
            for (int i = 0; i < match.numberOfRanges; ++i) {
                DebugLog(@"-> %@", [content substringWithRange:[match rangeAtIndex:i]]);
            }
        }
    }
    return matches;
}
+(NSTextCheckingResult*) expression_findfistMatch:(NSString*)content regex:(NSString*) pattern
{
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:nil error:nil];
    
    NSTextCheckingResult *match = [regex firstMatchInString:content options:nil range:NSMakeRange(0, content.length)];
    return match;
    //    if (matches) {
    //        for (NSTextCheckingResult *match in matches) {
    //            for (int i = 0; i < match.numberOfRanges; ++i) {
    //                DebugLog(@"-> %@", [content substringWithRange:[match rangeAtIndex:i]]);
    //            }
    //        }
    //    }
    //    return matches;
}
+ (CGRect)rectVAlign:(CGRect )parent rect:(CGRect)rect vAlign:(NSString*)vAlign
{
    //    double cx=parent.origin.x+parent.size.width/2;
    //    double cy=parent.origin.y+parent.size.height/2;
    CGPoint centerpoint= CGPointMake(parent.origin.x+parent.size.width/2,parent.origin.y+parent.size.height/2);
    
    if([vAlign.lowercaseString isEqualToString:@"middle"])
    {
        rect=CGRectMake(rect.origin.x, centerpoint.y-rect.size.height/2, rect.size.width, rect.size.height);
    }
    
    return rect;
    
}
@end
