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.

75 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. /**
  20. Calculates and applies a sequence of changes to convert one text string into
  21. another.
  22. Once created, the TextDiff object contains an array of change objects, where
  23. each change can be either an insertion or a deletion. When applied in order
  24. to the original string, these changes will convert it to the target string.
  25. @tags{Core}
  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. } // namespace juce