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.

78 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_TEXTDIFF_JUCEHEADER__
  19. #define __JUCE_TEXTDIFF_JUCEHEADER__
  20. /**
  21. Calculates and applies a sequence of changes to convert one text string into
  22. another.
  23. Once created, the TextDiff object contains an array of change objects, where
  24. each change can be either an insertion or a deletion. When applied in order
  25. to the original string, these changes will convert it to the target string.
  26. */
  27. class JUCE_API TextDiff
  28. {
  29. public:
  30. /** Creates a set of diffs for converting the original string into the target. */
  31. TextDiff (const String& original,
  32. const String& target);
  33. /** Applies this sequence of changes to the original string, producing the
  34. target string that was specified when generating them.
  35. Obviously it only makes sense to call this function with the string that
  36. was originally passed to the constructor. Any other input will produce an
  37. undefined result.
  38. */
  39. String appliedTo (String text) const;
  40. /** Describes a change, which can be either an insertion or deletion. */
  41. struct Change
  42. {
  43. String insertedText; /**< If this change is a deletion, this string will be empty; otherwise,
  44. it'll be the text that should be inserted at the index specified by start. */
  45. int start; /**< Specifies the character index in a string at which text should be inserted or deleted. */
  46. int length; /**< If this change is a deletion, this specifies the number of characters to delete. For an
  47. insertion, this is the length of the new text being inserted. */
  48. /** Returns true if this change is a deletion, or false for an insertion. */
  49. bool isDeletion() const noexcept;
  50. /** Returns the result of applying this change to a string. */
  51. String appliedTo (const String& original) const noexcept;
  52. };
  53. /** The list of changes required to perform the transformation.
  54. Applying each of these, in order, to the original string will produce the target.
  55. */
  56. Array<Change> changes;
  57. };
  58. #endif // __JUCE_TEXTDIFF_JUCEHEADER__