summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bytestring.cpp
AgeCommit message (Collapse)Author
2017-09-18Convert string class namesRyan Harrison
Automated using git grep & sed. Replace StringC classes with StringView classes. Remove the CFX_ prefix and put string classes in fxcrt namespace. Change AsStringC() to AsStringView(). Rename tests from TEST(fxcrt, *String*Foo) to TEST(*String*, Foo). Couple of tests needed to have their names regularlized. BUG=pdfium:894 Change-Id: I7ca038685c8d803795f3ed02545124f7a224c83d Reviewed-on: https://pdfium-review.googlesource.com/14151 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-09-13Avoid double va_list traversal in CFX_WideString::FormatVTom Sepez
Speculative fix for bug. Also remove FX_VA_COPY as va_copy should be fine on all ports nowdays (we think). Bug: 763965 Change-Id: I5c321d5624d00b3b2f262ec599e4382f02b744ff Reviewed-on: https://pdfium-review.googlesource.com/13790 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-09-06Convert FX_STRSIZE int->size_tRyan Harrison
Change the underlying type for FX_STRSIZE to size_t from int. This will make the value unsigned and thus all values in the range of the type will be valid. This allows for the final remove of negative length strings, but also introduces a some casting and functional errors, since many parts of the code base assume that FX_STRSIZE is int or another signed type. This also CL fixes these errors. BUG=pdfium:828 Change-Id: I231dca59e96fc9330cbb099eecbdfc41fcf86f5b Reviewed-on: https://pdfium-review.googlesource.com/11830 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-09-01Fix integer overflow in Buffer_itoa when passing INT_MIN.Henrique Nakashima
Bug: chromium:760034 Change-Id: Id0862749b1454e065de4de7d746a27e78ac58e30 Reviewed-on: https://pdfium-review.googlesource.com/12730 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-31Remove unused FXFORMAT_HEX and FXFORMAT_CAPITAL.Henrique Nakashima
Change-Id: I13140ea4242db4b0860f8fdd164f50d1745c0794 Reviewed-on: https://pdfium-review.googlesource.com/12790 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-31Move methods string methods to fx_string.cppDan Sinclair
This CL creates an fx_string.cpp and moves any methods defined in fx_string.h into the .cpp file. Change-Id: I64c310b9be6d8f4c3be633a22884023c0b16fc1b Reviewed-on: https://pdfium-review.googlesource.com/12671 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-08-30Move CFX_UTF8Decoder out of fx_basicDan Sinclair
This CL moves CFX_UTF8Decoder out of fx_basic and includes where needed. Change-Id: I1a093a8a77bbefcc90fbb2f81b1da65bfc0512bf Reviewed-on: https://pdfium-review.googlesource.com/12411 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-08-30Convert int* references to FX_STRSIZERyan Harrison
Through out the code base there are numerous places where variables are declared using a signed integer type when interacting with the string classes, since they assume that FX_STRSIZE is 'int'. As part of changing the underling type of FX_STRSIZE to be unsigned, these locations are being changed to use FX_STRSIZE. This is necessary as part of converting the type, but has been broken off into a separate CL, since it should be low risk. Some related cleanups that are low risk are included as part of this CL. BUG=pdfium:828 Change-Id: Ifaae54ad195ccde0fe8672f71271d29a6ebd65fd Reviewed-on: https://pdfium-review.googlesource.com/12210 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-08-25Add help IsValid* methods to string classeschromium/3198chromium/3197Ryan Harrison
The various string classes, CFX_ByteString, CFX_ByteStringC, CFX_WideString, and CFX_WideStringC, have many conditionals that are effectively determining if a value is a valid index or length. This CL refactors the logic into one place per class, so it only needs to be changed once if its behaviour needs to change. It also make the some of the methods stricter on the inputs they will accept. BUG=pdfium:828 Change-Id: Iadcdaa34a6d862a2804485770027179c89dc6956 Reviewed-on: https://pdfium-review.googlesource.com/12030 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-23Convert string Find methods to return an OptionalRyan Harrison
The Find and ReverseFind methods for WideString, WideStringC, ByteString, and ByteStringC have been converted from returning a raw FX_STRSIZE, to returning Optional<FX_STRSIZE>, so that success/failure can be indicated without using FX_STRNPOS. This allows for removing FX_STRNPOS and by association makes the conversion of FX_STRSIZE to size_t easier, since it forces checking the return value of Find to be explictly done as well as taking the error value out of the range of FX_STRSIZE. New Contains methods have been added for cases where the success or failure is all the call site to Find cared about, and the actual position was ignored. BUG=pdfium:828 Change-Id: Id827e508c8660affa68cc08a13d96121369364b7 Reviewed-on: https://pdfium-review.googlesource.com/11350 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-15Remove GetAt from string classesRyan Harrison
This method duplicates the behaviour of the const [] operator and doesn't offer any additional safety. Folding them into one implementation. SetAt is retained, since implementing the non-const [] operator to replace SetAt has potential performance concerns. Specifically many non-obvious cases of reading an element using [] will cause a realloc & copy. BUG=pdfium:860 Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67 Reviewed-on: https://pdfium-review.googlesource.com/10870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-11Add checks of index operations on string classesRyan Harrison
Specifically the index parameter passed in to GetAt(), SetAt() and operator[] are now being tested to be in bounds. BUG=chromium:752480, pdfium:828 Change-Id: I9e94d58c98a8eaaaae53cd0e3ffe2123ea17d8c4 Reviewed-on: https://pdfium-review.googlesource.com/10651 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-10Make CFX_ByteString(ostringstream) const.Henrique Nakashima
Change-Id: I782379cc7f93b93ed34a5d0a39ee2f198c650465 Reviewed-on: https://pdfium-review.googlesource.com/10430 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
2017-08-02Remove unused FromUnicode methodRyan Harrison
A helper method for FromUnicode existed that converted wchar_t* to CFX_WideString before calling the remaining FromUnicode. This method is not used in the code base, so it has been removed. This simplifies converting FX_STRSIZE to be unsigned, since one of parameters to this method was of type FX_STRSIZE. BUG=pdfium:828 Change-Id: I3da677b84ac3b82ba48497e26d2ac80dd14302e6 Reviewed-on: https://pdfium-review.googlesource.com/9910 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-08-02Remove parameter from GetIDRyan Harrison
All of the call sites for this method used the default value, so it has been removed. This simplifies converting FX_STRSIZE to be unsigned, since the removed parameter was of this type. BUG=pdfium:828 Change-Id: I369285aed561731ab34ec6d30de0d21fb3431492 Reviewed-on: https://pdfium-review.googlesource.com/9891 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-08-02Remove support for out of bounds params in DeleteRyan Harrison
The existing implementation of Delete on the string classes handles some cases where the range being deleted is out of bounds by clipping it to the valid range. This behaviour can lead to programming problems in the calling code being masked by the fact the Delete method still does something. The new version of these methods does an early return if the parameters are invalid. This change also effectively removes support for negative string sizes from the Delete method, so converting FX_STRSIZE to be unsigned will be easier. BUG=pdfium:828 Change-Id: Idbb4a62f70a75eba06e7809e011b25da2d7404c4 Reviewed-on: https://pdfium-review.googlesource.com/9890 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-08-02Rewrite how string Insert() methods handle out of bound indicesRyan Harrison
The existing behaviour was to clamp the provided index to the valid bounds. This would lead to programming errors being hidden, since inserting would still do something even if the index calculation was wrong. The behaviour of these methods has been changed to instead early return when this occurs, returning the old length value. The caller can check if the call to Insert actually did anything by comparing the returned value to the length before calling insert. All of the existing calls to Insert have been tested by running all of the tests with asserts in the Insert method to check the index is in bounds. Additionally the call sites have been manually inspected. The majority of them are of the form Insert(0, foo) and the rest tend to be in a loop advancing from 0 to length. Convenience methods InsertAtFront/InsertAtBack have been added to handle calling Insert when the intent is for the character to be added to the beginning or end of the string. Existing call sites to Insert that do this have been converted. This work was originally being performed to check if there would be any issues in these methods with making FX_STRSIZE unsigned. BUG=pdfium:828 Change-Id: I60cee5ad45338aa8ed46569de7bcc78a76db18f7 Reviewed-on: https://pdfium-review.googlesource.com/9870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-08-01Remove support for negative params to ReleaseBuffer()Ryan Harrison
This CL removes the default param value for this method, which was negative. It also adds in a method to get buffer lengths, so that the callsites can explictly passing in the length of the buffer if they were using the default value previously. BUG=pdfium:828 Change-Id: I0170771ee81970b8b601631015ab3e6e39fea8ea Reviewed-on: https://pdfium-review.googlesource.com/9790 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-08-01Replace raw value for constant error value in string operationsRyan Harrison
Currently Find() and other methods that return a FX_STRSIZE return -1 to indicate error/failure. This means that there is a lot of magic numbers and magic checks floating around. The standard library for similar operations uses a npos constant. This CL implements FX_STRNPOS, and replaces usages of magic number checking. It also does some type cleanup along the way where it was obvious that FX_STRSIZE should be being used. Removing the magic numbers should make eventually changing FX_STRSIZE to be unsigned easier in the future. BUG=pdfium:828 Change-Id: I67e481e44cf2f75a1698afa8fbee4f375a74c490 Reviewed-on: https://pdfium-review.googlesource.com/9651 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-07-27Remove single param Mid() method from string classesRyan Harrison
This support is being removed from CFX_ByteString, CFX_ByteStringC, CFX_WideString, and CFX_WideStringC. This standardizes all of these classes to only have one Mid method that takes in 2 params, offset and count. Count now must be positive. The old behaviour of calculating the length for the user if -1 is passed in for the count has been removed. This work is in preperation for converting these classes to not accept negative lengths anywhere and thus make the underlying size type unsigned. BUG=pdfium:828 Change-Id: I5f15e7b7b00b264231817f143e2da88ee6f69e7b Reviewed-on: https://pdfium-review.googlesource.com/9430 Reviewed-by: (OOO Jul 28 - Aug 8) dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-07-19Rename StringCs c_str() to unterminated_c_str().Tom Sepez
Since there is no guarantee of termination if the StringC was extracted from a snippet of another string. Make it more obvious that things like strlen(str.unterminated_c_str()) might be a bad idea. Change-Id: I7832248ed89ebbddf5c0bcd402aac7d40ec2adc2 Reviewed-on: https://pdfium-review.googlesource.com/8170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2017-06-28Add << overload for CFX_StringCTemplate classeschromium/3144Ryan Harrison
BUG=pdfium:790 Change-Id: I4a3623dc0daac6ff8407c09cd00e9f2e4e5dd2d7 Reviewed-on: https://pdfium-review.googlesource.com/7051 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-06-27Adding overload for ostream << CFX_ByteStringHenrique Nakashima
Bug: pdfium:731 Change-Id: I285332c8f9d988327e8633cb0746af2b76c401e5 Reviewed-on: https://pdfium-review.googlesource.com/6911 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-06-09Revert "Revert "Adding constructor of CFX_ByteString that takes a ↵Henrique Nakashima
std::ostringstream."" This reverts commit 53827cbbfebae66dd31f7aa30d3ee5c88716897a. Reason for revert: Rollforward of original CL - test failures were flakes. Original change's description: > Revert "Adding constructor of CFX_ByteString that takes a std::ostringstream." > > This reverts commit 4633d52736c4b926eceb1e18c4b379ff57fd31fa. > > Reason for revert: windows_xfa_clang broke? > > Original change's description: > > Adding constructor of CFX_ByteString that takes a std::ostringstream. > > > > Bug: pdfium:731 > > Change-Id: Ia0734deb3f309732dccae5c0cf6131d32713e87a > > Reviewed-on: https://pdfium-review.googlesource.com/6394 > > Reviewed-by: dsinclair <dsinclair@chromium.org> > > Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> > > TBR=dsinclair@chromium.org,hnakashima@chromium.org > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: pdfium:731 > > Change-Id: I674aa1be12d6777c4d565d3131910ac5a11d8dc0 > Reviewed-on: https://pdfium-review.googlesource.com/6395 > Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> > Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> TBR=dsinclair@chromium.org,pdfium-reviews@googlegroups.com,hnakashima@chromium.org No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: pdfium:731 Change-Id: I4a31a1a6bdb128016183c1059f0bfe1fa559a89e Reviewed-on: https://pdfium-review.googlesource.com/6434 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
2017-06-08Revert "Adding constructor of CFX_ByteString that takes a std::ostringstream."Henrique Nakashima
This reverts commit 4633d52736c4b926eceb1e18c4b379ff57fd31fa. Reason for revert: windows_xfa_clang broke? Original change's description: > Adding constructor of CFX_ByteString that takes a std::ostringstream. > > Bug: pdfium:731 > Change-Id: Ia0734deb3f309732dccae5c0cf6131d32713e87a > Reviewed-on: https://pdfium-review.googlesource.com/6394 > Reviewed-by: dsinclair <dsinclair@chromium.org> > Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> TBR=dsinclair@chromium.org,hnakashima@chromium.org No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: pdfium:731 Change-Id: I674aa1be12d6777c4d565d3131910ac5a11d8dc0 Reviewed-on: https://pdfium-review.googlesource.com/6395 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
2017-06-08Adding constructor of CFX_ByteString that takes a std::ostringstream.Henrique Nakashima
Bug: pdfium:731 Change-Id: Ia0734deb3f309732dccae5c0cf6131d32713e87a Reviewed-on: https://pdfium-review.googlesource.com/6394 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
2017-05-04Cleanup CFX_CharMapDan Sinclair
This CL removes the CFX_CharMap class and moves the two static methods into the files in which they're used. Change-Id: I8ff7cbfd7f1ef3970e39c77ffa3439099f7fec02 Reviewed-on: https://pdfium-review.googlesource.com/4873 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-04-25Use fx_extension.h utilities in more places.Lei Zhang
Change-Id: Iba1aa793567e69acc3cc1acbd5b9a9f531c80b7a Reviewed-on: https://pdfium-review.googlesource.com/4453 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2017-04-07Create initializer-list ctor for strings.Tom Sepez
Also use safe arithmetic for two-arg ctor. Change-Id: I5d541d9b2d5fe5b939f4cc8c22cf034f5cb01176 Reviewed-on: https://pdfium-review.googlesource.com/3955 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-04-03Drop FXSYS_ from mem methodsDan Sinclair
This Cl drops the FXSYS_ from mem methods which are the same on all platforms. Bug: pdfium:694 Change-Id: I9d5ae905997dbaaec5aa0b2ae4c07358ed9c6236 Reviewed-on: https://pdfium-review.googlesource.com/3613 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-03-31Re-arrange fxcrt string files to match naming.Tom Sepez
The top-level fx_string.h is kept to include all strings. Put all fx_atof code in fx_basic_util.cpp rather than header. Change-Id: I61fe768f2e1ddf8438d27e410929f4cff918a9a3 Reviewed-on: https://pdfium-review.googlesource.com/3530 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>