A set of classes for parsing, evaluating, and formatting die roll strings.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SA_DiceErrorHandling.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. void addErrorToExpression (NSString *error, NSMutableDictionary *expression)
  11. {
  12. if(error == nil || expression == nil)
  13. {
  14. return;
  15. }
  16. if(expression[SA_DB_ERRORS] == nil)
  17. {
  18. expression[SA_DB_ERRORS] = [NSMutableArray <NSString *> arrayWithObjects:error, nil];
  19. }
  20. else
  21. {
  22. [expression[SA_DB_ERRORS] addObject:error];
  23. }
  24. }
  25. // Top-level errors only (i.e. the expression tree is not traversed in search
  26. // of deeper errors).
  27. void addErrorsFromExpressionToExpression (NSDictionary *sourceExpression, NSMutableDictionary *targetExpression)
  28. {
  29. if(sourceExpression == nil || targetExpression == nil)
  30. {
  31. return;
  32. }
  33. if(sourceExpression[SA_DB_ERRORS] == nil || [sourceExpression[SA_DB_ERRORS] count] == 0)
  34. {
  35. // Do absolutely nothing; no errors to add.
  36. }
  37. else if(targetExpression[SA_DB_ERRORS] == nil)
  38. {
  39. targetExpression[SA_DB_ERRORS] = [NSMutableArray <NSString *> arrayWithArray:sourceExpression[SA_DB_ERRORS]];
  40. }
  41. else
  42. {
  43. [targetExpression[SA_DB_ERRORS] addObjectsFromArray:sourceExpression[SA_DB_ERRORS]];
  44. }
  45. }
  46. NSArray <NSString *> *getErrorsForExpression (NSDictionary *expression)
  47. {
  48. return ([expression[SA_DB_ERRORS] count] > 0) ? expression[SA_DB_ERRORS] : nil;
  49. }