FMStatementQuotedRecogniser.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // FMStatementQuotedRecogniser.h
  3. // FMDB
  4. //
  5. // Created by openthread on 3/5/14.
  6. // Copyright (c) 2014 openthread. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "FMStatementTokenRecogniser.h"
  10. /**
  11. * The FMStatementQuotedRecogniser class is used to recognise quoted literals in the input string. This can be used for quoted strings, characters, comments and many other things.
  12. *
  13. * Quoted tokens are recognised via a start string and end string. You may optionally add an escape sequence string that stops the end quote being recognised at that point in the input.
  14. * You may optionally provide a block used to replace escape sequences with their actual meaning. If you don't provide an escape replcement block it is assumed that the character
  15. * following the escape sequence replaces the whole sequence.
  16. *
  17. * Finally, you may also provide a maximum length for the quoted sequence to recognise. If you want to recognise strings of any length, pass NSNotFound.
  18. */
  19. @interface FMStatementQuotedRecogniser : NSObject <FMStatementTokenRecogniser>
  20. ///---------------------------------------------------------------------------------------
  21. /// @name Creating and Initialising a Quoted Recogniser
  22. ///---------------------------------------------------------------------------------------
  23. /**
  24. * Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote.
  25. *
  26. * @param startQuote A string that indicates the beginning of a quoted literal.
  27. * @param endQuote A string that indicates the end of the quoted literal.
  28. * @param name The name to attach to recognised tokens.
  29. * @return Returns a FMStatementQuotedRecogniser that recognises C like identifiers.
  30. *
  31. * @see quotedRecogniserWithStartQuote:endQuote:escapeSequence:name:
  32. * @see quotedRecogniserWithStartQuote:endQuote:escapeSequence:maximumLength:name:
  33. */
  34. + (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote name:(NSString *)name;
  35. /**
  36. * Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string.
  37. *
  38. * @param startQuote A string that indicates the beginning of a quoted literal.
  39. * @param endQuote A string that indicates the end of the quoted literal.
  40. * @param escapeSequence A string that indicates an escaped character.
  41. * @param name The name to attach to recognised tokens.
  42. * @return Returns a FMStatementQuotedRecogniser that recognises C like identifiers.
  43. *
  44. * @see quotedRecogniserWithStartQuote:endQuote:name:
  45. * @see quotedRecogniserWithStartQuote:endQuote:escapeSequence:maximumLength:name:
  46. */
  47. + (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence name:(NSString *)name;
  48. /**
  49. * Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
  50. *
  51. * @param startQuote A string that indicates the beginning of a quoted literal.
  52. * @param endQuote A string that indicates the end of the quoted literal.
  53. * @param escapeSequence A string that indicates an escaped character.
  54. * @param maximumLength The maximum length of the resulting string.
  55. * @param name The name to attach to recognised tokens.
  56. * @return Returns a FMStatementQuotedRecogniser that recognises C like identifiers.
  57. *
  58. * @see quotedRecogniserWithStartQuote:endQuote:name:
  59. * @see quotedRecogniserWithStartQuote:endQuote:escapeSequence:name:
  60. * @see initWithStartQuote:endQuote:escapeSequence:maximumLength:name:
  61. */
  62. + (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence maximumLength:(NSUInteger)maximumLength name:(NSString *)name;
  63. /**
  64. * Initialises a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
  65. *
  66. * @param startQuote A string that indicates the beginning of a quoted literal.
  67. * @param endQuote A string that indicates the end of the quoted literal.
  68. * @param escapeSequence A string that indicates an escaped character.
  69. * @param maximumLength The maximum length of the resulting string.
  70. * @param name The name to attach to recognised tokens.
  71. * @return Returns a FMStatementQuotedRecogniser that recognises C like identifiers.
  72. *
  73. * @see quotedRecogniserWithStartQuote:endQuote:escapeSequence:maximumLength:name:
  74. */
  75. - (id)initWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence maximumLength:(NSUInteger)maximumLength name:(NSString *)name;
  76. ///---------------------------------------------------------------------------------------
  77. /// @name Configuring a Quoted Recogniser
  78. ///---------------------------------------------------------------------------------------
  79. /**
  80. * Determines the string used to indicate the start of the quoted literal.
  81. *
  82. * @see endQuote
  83. */
  84. @property (readwrite,nonatomic,copy) NSString *startQuote;
  85. /**
  86. * Determines the string used to indicate the end of the quoted literal.
  87. *
  88. * @see startQuote
  89. */
  90. @property (readwrite,nonatomic,copy) NSString *endQuote;
  91. /**
  92. * Determines the string used to indicate an escaped character in the quoted literal.
  93. */
  94. @property (readwrite,nonatomic,copy) NSString *escapeSequence;
  95. /**
  96. * If `YES`, quoted string will contains `escapeSequence`.
  97. * If `NO`, quoted string will not contains `escapeSequence`.
  98. * Default is `NO`.
  99. */
  100. @property (nonatomic,assign) BOOL shouldQuoteEscapeSequence;
  101. /**
  102. * Determines how much of the input string to consume when an escaped literal is found, and what to replace it with.
  103. */
  104. @property (readwrite,nonatomic,copy) NSString *(^escapeReplacer)(NSString *tokenStream, NSUInteger *quotePosition);
  105. /**
  106. * Determines the maximum length of the quoted literal not including quotes. To indicate the literal can be any length specify NSNotFound.
  107. */
  108. @property (readwrite,nonatomic,assign) NSUInteger maximumLength;
  109. /**
  110. * Determines the name of the token produced.
  111. */
  112. @property (readwrite,nonatomic,copy) NSString *name;
  113. @end