The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_TEXTDIFF_H_INCLUDED
  24. #define JUCE_TEXTDIFF_H_INCLUDED
  25. /**
  26. Calculates and applies a sequence of changes to convert one text string into
  27. another.
  28. Once created, the TextDiff object contains an array of change objects, where
  29. each change can be either an insertion or a deletion. When applied in order
  30. to the original string, these changes will convert it to the target string.
  31. */
  32. class JUCE_API TextDiff
  33. {
  34. public:
  35. /** Creates a set of diffs for converting the original string into the target. */
  36. TextDiff (const String& original,
  37. const String& target);
  38. /** Applies this sequence of changes to the original string, producing the
  39. target string that was specified when generating them.
  40. Obviously it only makes sense to call this function with the string that
  41. was originally passed to the constructor. Any other input will produce an
  42. undefined result.
  43. */
  44. String appliedTo (String text) const;
  45. /** Describes a change, which can be either an insertion or deletion. */
  46. struct Change
  47. {
  48. String insertedText; /**< If this change is a deletion, this string will be empty; otherwise,
  49. it'll be the text that should be inserted at the index specified by start. */
  50. int start; /**< Specifies the character index in a string at which text should be inserted or deleted. */
  51. int length; /**< If this change is a deletion, this specifies the number of characters to delete. For an
  52. insertion, this is the length of the new text being inserted. */
  53. /** Returns true if this change is a deletion, or false for an insertion. */
  54. bool isDeletion() const noexcept;
  55. /** Returns the result of applying this change to a string. */
  56. String appliedTo (const String& original) const noexcept;
  57. };
  58. /** The list of changes required to perform the transformation.
  59. Applying each of these, in order, to the original string will produce the target.
  60. */
  61. Array<Change> changes;
  62. };
  63. #endif // JUCE_TEXTDIFF_H_INCLUDED