codeStringParsingTools.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Extracts the characters between two markers (for eg, between "(" and ")"). The function handles nested markers as well as markers inside strings (delimited by ", ' or `) and comments
  3. * @param markerOpen opening marker
  4. * @param markerClose closing marker
  5. * @param block code block to parse
  6. * @param startIndex starting index in block where the extraction must start. The character at block[startIndex] should be the markerOpen character!
  7. * @returns index of the last character for the extraction (or -1 if the string is invalid - no matching closing marker found). The string to extract (without the markers) is the string between startIndex + 1 and the returned value (exclusive)
  8. */
  9. export declare function ExtractBetweenMarkers(markerOpen: string, markerClose: string, block: string, startIndex: number): number;
  10. /**
  11. * Parses a string and skip whitespaces
  12. * @param s string to parse
  13. * @param index index where to start parsing
  14. * @returns the index after all whitespaces have been skipped
  15. */
  16. export declare function SkipWhitespaces(s: string, index: number): number;
  17. /**
  18. * Checks if a character is an identifier character (meaning, if it is 0-9, A-Z, a-z or _)
  19. * @param c character to check
  20. * @returns true if the character is an identifier character
  21. */
  22. export declare function IsIdentifierChar(c: string): boolean;
  23. /**
  24. * Removes the comments of a code block
  25. * @param block code block to parse
  26. * @returns block with the comments removed
  27. */
  28. export declare function RemoveComments(block: string): string;
  29. /**
  30. * Finds the first occurrence of a character in a string going backward
  31. * @param s the string to parse
  32. * @param index starting index in the string
  33. * @param c the character to find
  34. * @param c2 an optional second character to find
  35. * @returns the index of the character if found, else -1
  36. */
  37. export declare function FindBackward(s: string, index: number, c: string, c2?: string): number;
  38. /**
  39. * Escapes a string so that it is usable as a regular expression
  40. * @param s string to escape
  41. * @returns escaped string
  42. */
  43. export declare function EscapeRegExp(s: string): string;