Advertisement
Guest User

russianDeclension obj-c

a guest
Jun 19th, 2014
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. + (NSString*) russianDeclensionForNum:(NSInteger)num one:(NSString*)one two:(NSString*)two five:(NSString*)five {
  2.     return [NSString russianDeclensionForStr:[NSString stringWithFormat:@"%d", num] one:one two:two five:five];
  3. }
  4.  
  5. + (NSString*) russianDeclensionForStr:(NSString*)str one:(NSString*)one two:(NSString*)two five:(NSString*)five {
  6.     NSString *res = nil;
  7.     if ([str hasSuffix:@"1"] && ![str hasSuffix:@"11"]) {
  8.         res = [NSString stringWithFormat:@"%@ %@", str, one];
  9.     } else if([str hasSuffix:@"11"]
  10.             || [str hasSuffix:@"12"]
  11.             || [str hasSuffix:@"13"]
  12.             || [str hasSuffix:@"14"]) {
  13.         res = [NSString stringWithFormat:@"%@ %@", str, five];
  14.     } else if ([str hasSuffix:@"2"] || [str hasSuffix:@"3"] || [str hasSuffix:@"4"]) {
  15.         res = [NSString stringWithFormat:@"%@ %@", str, two];
  16.     } else if ([str hasSuffix:@"0"]
  17.              || [str hasSuffix:@"5"]
  18.              || [str hasSuffix:@"6"]
  19.              || [str hasSuffix:@"7"]
  20.              || [str hasSuffix:@"8"]
  21.              || [str hasSuffix:@"9"]) {
  22.         res = [NSString stringWithFormat:@"%@ %@", str, five];
  23.     } else {
  24.         res = str;
  25.     }
  26.     return res;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement