<commit_before>//
//  MacrosBase.h
//  CocoaTouchHelpers
//
//  Created by <NAME> on 11/4/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#ifndef CocoaTouchHelpers_MacrosBase_h
#define CocoaTouchHelpers_MacrosBase_h

//===

// http://stackoverflow.com/questions/3339722/check-iphone-ios-version
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//===

// http://stackoverflow.com/questions/5559652/how-do-i-detect-the-orientation-of-the-device-on-ios

#define isDOrientationUnknown [[UIDevice currentDevice] orientation] == UIDeviceOrientationUnknown
#define isDPortraitNormal [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait
#define isDOrientationDefault isDPortraitNormal
#define isDPortraitUpsideDown [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown
#define isDPortrait isDPortraitNormal || isDPortraitUpsideDown
#define isDLandscapeLeft [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft
#define isDLandscapeRight [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight
#define isDLandscape isDLandscapeLeft || isDLandscapeRight
#define isDFaceUp [[UIDevice currentDevice] orientation] == UIDeviceOrientationFaceUp
#define isDFaceDown [[UIDevice currentDevice] orientation] == UIDeviceOrientationFaceDown

#define isUIPortraitNormal [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait
#define isUIOrientationDefault isUIPortraitNormal
#define isUIPortraitUpsideDown [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown
#define isUIPortrait isUIPortraitNormal || isUIPortraitUpsideDown
#define isUILandscapeLeft [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft
#define isUILandscapeRight [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight
#define isUILandscape isUILandscapeLeft || isUILandscapeRight

//===

#define thisMoment [NSDate date]

//===

#define isPhone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

// is it iPhone with retina 4 inches (iPhone 5)?
#define isRetina4 (isPhone && ([UIScreen mainScreen].bounds.size.height == 568))

#define isRetina ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))

#define mainScreenSize [UIScreen mainScreen].bounds.size

//===

#define UIViewAutoresizingAll UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

#define UIViewAutoresizingTop UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

#define UIViewAutoresizingBottom UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

//===

#define zeroView [[UIView alloc] initWithFrame:CGRectZero]
#define animate(simpleBlock) [UIView animateWithDuration:defaultAnimationDuration animations:simpleBlock]

//===

#define bgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

#define runBg(simpleBlock) dispatch_async(bgQueue, simpleBlock)
#define runMain(simpleBlock) dispatch_async(dispatch_get_main_queue(), simpleBlock)

//===

#define weakSelfMacro __weak typeof(self) weakSelf = self
#define thisOperationMacro __weak NSBlockOperation *thisOperation = nil
#define errorMacro NSError *error = nil

#define waitFor(condition) while (!condition) { /* NSLog(@"Waiting for condition..."); */ }
#define waitWhile(condition) while (condition) { /* NSLog(@"Waiting..."); */ }

//===

#define isObjectForKeySupported(object) ([object isKindOfClass:[NSObject class]] && [object respondsToSelector:@selector(objectForKey:)])

#define isClassOfObject(class, object) [object isKindOfClass:class]

#define isNonZeroLength(object) ([object respondsToSelector:@selector(length)] && ([object length] > 0))
#define isNonZeroData(object) (isClassOfObject([NSData class], object) && isNonZeroLength(object))<commit_msg>Do not init NSError with 'nil'<commit_after>//
//  MacrosBase.h
//  CocoaTouchHelpers
//
//  Created by <NAME> on 11/4/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#ifndef CocoaTouchHelpers_MacrosBase_h
#define CocoaTouchHelpers_MacrosBase_h

//===

// http://stackoverflow.com/questions/3339722/check-iphone-ios-version
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//===

// http://stackoverflow.com/questions/5559652/how-do-i-detect-the-orientation-of-the-device-on-ios

#define isDOrientationUnknown [[UIDevice currentDevice] orientation] == UIDeviceOrientationUnknown
#define isDPortraitNormal [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait
#define isDOrientationDefault isDPortraitNormal
#define isDPortraitUpsideDown [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown
#define isDPortrait isDPortraitNormal || isDPortraitUpsideDown
#define isDLandscapeLeft [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft
#define isDLandscapeRight [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight
#define isDLandscape isDLandscapeLeft || isDLandscapeRight
#define isDFaceUp [[UIDevice currentDevice] orientation] == UIDeviceOrientationFaceUp
#define isDFaceDown [[UIDevice currentDevice] orientation] == UIDeviceOrientationFaceDown

#define isUIPortraitNormal [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait
#define isUIOrientationDefault isUIPortraitNormal
#define isUIPortraitUpsideDown [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown
#define isUIPortrait isUIPortraitNormal || isUIPortraitUpsideDown
#define isUILandscapeLeft [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft
#define isUILandscapeRight [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight
#define isUILandscape isUILandscapeLeft || isUILandscapeRight

//===

#define thisMoment [NSDate date]

//===

#define isPhone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

// is it iPhone with retina 4 inches (iPhone 5)?
#define isRetina4 (isPhone && ([UIScreen mainScreen].bounds.size.height == 568))

#define isRetina ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))

#define mainScreenSize [UIScreen mainScreen].bounds.size

//===

#define UIViewAutoresizingAll UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

#define UIViewAutoresizingTop UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

#define UIViewAutoresizingBottom UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin

//===

#define zeroView [[UIView alloc] initWithFrame:CGRectZero]
#define animate(simpleBlock) [UIView animateWithDuration:defaultAnimationDuration animations:simpleBlock]

//===

#define bgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

#define runBg(simpleBlock) dispatch_async(bgQueue, simpleBlock)
#define runMain(simpleBlock) dispatch_async(dispatch_get_main_queue(), simpleBlock)

//===

#define weakSelfMacro __weak typeof(self) weakSelf = self
#define thisOperationMacro __weak NSBlockOperation *thisOperation = nil
#define errorMacro NSError *error

#define waitFor(condition) while (!condition) { /* NSLog(@"Waiting for condition..."); */ }
#define waitWhile(condition) while (condition) { /* NSLog(@"Waiting..."); */ }

//===

#define isObjectForKeySupported(object) ([object isKindOfClass:[NSObject class]] && [object respondsToSelector:@selector(objectForKey:)])

#define isClassOfObject(class, object) [object isKindOfClass:class]

#define isNonZeroLength(object) ([object respondsToSelector:@selector(length)] && ([object length] > 0))
#define isNonZeroData(object) (isClassOfObject([NSData class], object) && isNonZeroLength(object))
{'fraction_non_alphanumeric': 0.09662832989285364, 'fraction_numerical': 0.006487761722205839, 'mean_word_length': 8.59811320754717, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1031386', 'n_tokens_mistral': 3141, 'n_tokens_neox': 2973, 'n_words': 571}