Menu

#1293 Change parameter for AddCharUTF() to std::string_view

Committed
closed
scintilla (287)
5
2019-07-05
2019-05-28
Zufu Liu
No

As discussed at https://sourceforge.net/p/scintilla/bugs/2093/#ed26/c13e

The old ScintillaBase::AddCharUTF() is marked as deprecated.

I think treatAsDBCS can be removed, the unused bool parameter can be kept on the deprecated ScintillaBase::AddCharUTF().

1 Attachments

Discussion

  • Zufu Liu

    Zufu Liu - 2019-05-28

    Moved implementation of old AddCharUTF to ScintillaBase.cxx

     
  • Neil Hodgson

    Neil Hodgson - 2019-05-28

    That seems mostly worthwhile.

    One problem is that using string_view encourages use of strings that are not NUL-terminated. This won't be a problem for internal use but the data is sent as a macro record notification to the application. Applications may fail if there is no terminating NUL in a situation in which there was previously. Perhaps a std::string copy of the insertion is needed in the recordingMacro branch.

    Since the method signature is incompatible, it would be reasonable to make other changes now. The "UTF" part of the name is meaningless, abbreviations should be avoided, and the method is inserting at the caret position(s) not adding to the end, so I'd like to change the method name to InsertCharacter.

    This method may receive more options in the future, so, if the treatAsDBCS option were to be retained it should be an extendable enum class InsertionOption { Default, TreatAsDBCS };. If treatAsDBCS is removed then its simpler to not have an option parameter at this point as it can be added when needed with a default value.

     
  • Zufu Liu

    Zufu Liu - 2019-05-28

    It actual not NUL-terminated from cocoa.

    -               AddCharUTF(sv.data(), bytesInCharacter, false);
    +               AddCharUTF(sv.substr(0, bytesInCharacter));
    

    Should I make other changes (rename to InsertCharacter and remove treatAsDBCS, copy in recordingMacro) in one patch?

     
  • Zufu Liu

    Zufu Liu - 2019-05-29

    With these changes.

    Editor::AddChar and ScintillaWin::AddWString not renamed.

     
  • Neil Hodgson

    Neil Hodgson - 2019-05-30

    I have written this up on the mailing list so that platform layer maintainers can discuss any problems they have with the proposed changes.
    https://groups.google.com/d/topic/scintilla-interest/L6F_MiT0WEQ/discussion

    Not NUL-terminating on Cocoa currently does not mean it is safe for client code that is not currently built for Cocoa. It is also possible that clients on Cocoa are faulty but problems have not been reported.

     
  • Neil Hodgson

    Neil Hodgson - 2019-06-17
    • labels: --> scintilla
    • Group: Completed --> Committed
     
  • Neil Hodgson

    Neil Hodgson - 2019-06-17

    Committed as [e1e9f5]. Added 'const' inside IsAllSpacesOrTabs.

     

    Related

    Commit: [e1e9f5]

  • Neil Hodgson

    Neil Hodgson - 2019-07-05
    • status: open --> closed
     
  • Neil Hodgson

    Neil Hodgson - 2019-07-05

    Committed as [e1e9f5]. Added 'const' inside IsAllSpacesOrTabs.

     

    Related

    Commit: [e1e9f5]


Log in to post a comment.