NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators
In the case of a logical shift, the value of the last bit in the direction of the shift is lost (copied to the carry bit), and the first one becomes zero.
This is a binary operation, the operation of which is equivalent to applying a logical OR to each pair of bits that are at the same positions in the binary representations of the operands. In other words, if both the corresponding bits of the operands are 0, the binary bit of the result is 0; if at least one bit of the pair is 1, the binary bit of the result is 1.
This is a binary operation, the action of which is equivalent to applying a logical “AND” to each pair of bits that are at the same positions in the binary representations of the operands. In other words, if both corresponding bits of the operands are 1, the resulting binary bit is 1; if at least one bit of the pair is 0, the resulting binary bit is 0.
binaryNumber << n // bit left shift to "n" positions (digits) binaryNumber >> n // bit shift to the right by "n" positions (digits)
1 << n // where "n" is the number of positions (digits) to shift 1 << 0 // 00000001 shift to 0 bits 1 << 1 // 00000001 shift by 1 bits 1 << 3 // 00000001 shift by 3 bits 1 << 5 // 00000001 shift by 5 digits
1 << 0 | 1 << 3 | 1 << 5
The result obtained from applying the bitwise logical "OR" operation to different numbers with one set bit from a given set of numbers is always unique
1 << 0 & (1 << 0 | 1 << 3 | 1 << 5) = 1 << 0 1 << 3 & (1 << 0 | 1 << 3 | 1 << 5) = 1 << 3 1 << 5 & (1 << 0 | 1 << 3 | 1 << 5) = 1 << 5
1 << 1 & (1 << 0 | 1 << 3 | 1 << 5) ≠1 << 1 1 << 2 & (1 << 0 | 1 << 3 | 1 << 5) ≠1 << 2 1 << 4 & (1 << 0 | 1 << 3 | 1 << 5) ≠1 << 4
This is the specific data that is used for masking — the selection of individual bits or fields from several bits from a binary string or number.
By applying the bitwise logical "OR (OR)" operation to several numbers with one bit set, you can use the result as a bit mask to filter the original numbers from many others.
enum Groups { group_0 = 0, group_1 = 1 group_2 = 2, group_3 = 3, group_4 = 4, };
enum Groups { group_0 = 1 << 0, group_1 = 1 << 1, group_2 = 1 << 2, group_3 = 1 << 3, group_4 = 1 << 4 };
(1 << 2 | 1 << 3) = 0x55 1 << 2 & (1 << 2 | 1 << 3) = 1 << 2 1 << 3 & (1 << 2 | 1 << 3) = 1 << 3 1 << 1 & (1 << 2 | 1 << 3) ≠1 << 1 1 << 4 & (1 << 2 | 1 << 3) ≠1 << 4
(group_2 | group_3) = 0x55 group_2 & (group_2 | group_3) = group_2 group_3 & (group_2 | group_3) = group_3 group_1 & (group_2 | group_3) ≠group_1 group_4 & (group_2 | group_3) ≠group_4
typedef NS_OPTIONS(NSUInteger, NSRegularExpressionOptions) { NSRegularExpressionCaseInsensitive = 1 << 0, // Match letters in the pattern independent of case NSRegularExpressionAllowCommentsAndWhitespace = 1 << 1, // Ignore whitespace and #-prefixed comments in the pattern NSRegularExpressionIgnoreMetacharacters = 1 << 2, // Treat the entire pattern as a literal string NSRegularExpressionDotMatchesLineSeparators = 1 << 3, // Allow . to match any character, including line separators NSRegularExpressionAnchorsMatchLines = 1 << 4, // Allow ^ and $ to match the start and end of lines NSRegularExpressionUseUnixLineSeparators = 1 << 5, // Treat only \n as a line separator (otherwise, all standard line separators are used) NSRegularExpressionUseUnicodeWordBoundaries = 1 << 6 // Use Unicode TR#29 to specify word boundaries (otherwise, traditional regular expression word boundaries are used) };
typedef NS_OPTIONS(uint64_t, NSTextCheckingType) { // a single type NSTextCheckingTypeOrthography = 1ULL << 0, // language identification NSTextCheckingTypeSpelling = 1ULL << 1, // spell checking NSTextCheckingTypeGrammar = 1ULL << 2, // grammar checking NSTextCheckingTypeDate = 1ULL << 3, // date/time detection NSTextCheckingTypeAddress = 1ULL << 4, // address detection NSTextCheckingTypeLink = 1ULL << 5, // link detection NSTextCheckingTypeQuote = 1ULL << 6, // smart quotes NSTextCheckingTypeDash = 1ULL << 7, // smart dashes NSTextCheckingTypeReplacement = 1ULL << 8, // fixed replacements, such as copyright symbol for (c) NSTextCheckingTypeCorrection = 1ULL << 9, // autocorrection NSTextCheckingTypeRegularExpression = 1ULL << 10, // regular expression matches NSTextCheckingTypePhoneNumber = 1ULL << 11, // phone number detection NSTextCheckingTypeTransitInformation = 1ULL << 12 // transit (eg flight) info detection };
NSInteger group_masck = (group_2 | group_3) = 0x55; if ((group_masck & group_0) == group_0) { // , } if ((group_masck & group_1) == group_1) { // , } if ((group_masck & group_2) == group_2) { // , } if ((group_masck & group_3) == group_3) { // , } if ((group_masck & group_4) == group_4) { // , }
NSInteger group_masck = (1 << 2 | 1 << 3) = 0x55 if (((1 << 2 | 1 << 3) & 1 << 0) == 1 << 0) { // , } if (((1 << 2 | 1 << 3) & 1 << 1) == 1 << 1) { // , } if (((1 << 2 | 1 << 3) & 1 << 2) == 1 << 2) { // , } if (((1 << 2 | 1 << 3) & 1 << 3) == 1 << 3) { // , } if (((1 << 2 | 1 << 3) & 1 << 4) == 1 << 4) { // , }
NSInteger group_masck = (group_2 | group_3) = 0x55; id variable; for (int i = 0; i <= 4; i++) { switch (i) { case 0: { variable = value_0; } break; case 1: { variable = value_1; } break; case 2: { variable = value_2; } break; case 3: { variable = value_3; } break; case 4: { variable = value_4; } break; default: { //, } break; } if ((group_masck & 1ULL << i) == 1ULL << i) { // "variable" } }
BOOL msfDDstringCheckingStyle(NSString *string, tMSstringCheckingStyle stringCheckingStyle, BOOL allConditionsIsRequired, NSInteger minLengthOfString)
typedef enum tMSstringCheckingStyle: NSInteger { kMSstringCheckingStyle_digits = 1ULL << 0, // must-have only a digits kMSstringCheckingStyle_englishLetters = 1ULL << 1, // must-have only a English letters kMSstringCheckingStyle_russianLetters = 1ULL << 2, // must-have only a Russian letters kMSstringCheckingStyle_startWithLetter = 1ULL << 3, // the string necessarily start with a letter kMSstringCheckingStyle_upperAndLowerCaseLetters = 1ULL << 4, // must-have a uppercase and a lowercase letters kMSstringCheckingStyle_specialSymbols = 1ULL << 5, // must-have one or more special symbols "-" "." "+" "_" } tMSstringCheckingStyle;
msfDDstringCheckingStyle(NSString *string, tMSstringCheckingStyle kMSstringCheckingStyle_digits | kMSstringCheckingStyle_englishLetters, BOOL YES, NSInteger 8)
Source: https://habr.com/ru/post/279441/