A set of classes for parsing, evaluating, and formatting die roll strings.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SA_DiceErrorHandling.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // SA_DiceErrorHandling.m
  3. //
  4. // Copyright (c) 2016 Said Achmiz.
  5. //
  6. // This software is licensed under the MIT license.
  7. // See the file "LICENSE" for more information.
  8. #import "SA_DiceErrorHandling.h"
  9. #import "SA_DiceExpressionStringConstants.h"
  10. @implementation SA_DiceErrorHandler
  11. +(void) addError:(NSString *)error
  12. toExpression:(NSMutableDictionary *)expression {
  13. if (error == nil || expression == nil) {
  14. return;
  15. }
  16. if (expression[SA_DB_ERRORS] == nil) {
  17. expression[SA_DB_ERRORS] = [NSMutableArray <NSString *> arrayWithObjects:error, nil];
  18. } else {
  19. [expression[SA_DB_ERRORS] addObject:error];
  20. }
  21. }
  22. // Top-level errors only (i.e. the expression tree is not traversed in search
  23. // of deeper errors).
  24. +(void) addErrorsFromExpression:(NSDictionary *)sourceExpression
  25. toExpression:(NSMutableDictionary *)targetExpression {
  26. if (sourceExpression == nil || targetExpression == nil) {
  27. return;
  28. }
  29. if (sourceExpression[SA_DB_ERRORS] == nil || [sourceExpression[SA_DB_ERRORS] count] == 0) {
  30. // Do absolutely nothing; no errors to add.
  31. } else if(targetExpression[SA_DB_ERRORS] == nil) {
  32. targetExpression[SA_DB_ERRORS] = [NSMutableArray <NSString *> arrayWithArray:sourceExpression[SA_DB_ERRORS]];
  33. } else {
  34. [targetExpression[SA_DB_ERRORS] addObjectsFromArray:sourceExpression[SA_DB_ERRORS]];
  35. }
  36. }
  37. +(NSArray <NSString *> *) errorsForExpression:(NSDictionary *)expression {
  38. return ([expression[SA_DB_ERRORS] count] > 0) ? expression[SA_DB_ERRORS] : nil;
  39. }
  40. @end