Bug 85154

Summary: Add String::startsWith() and endsWith() for string literals
Product: WebKit Reporter: Benjamin Poulain <benjamin>
Component: Web Template FrameworkAssignee: Benjamin Poulain <benjamin>
Status: RESOLVED FIXED    
Severity: Normal CC: gustavo, japhet, macpherson, menard, tkent, webkit.review.bot, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch darin: review+

Benjamin Poulain
Reported 2012-04-28 23:35:15 PDT
Add String::startsWith() and endsWith() for string literals
Attachments
Patch (20.96 KB, patch)
2012-04-29 00:22 PDT, Benjamin Poulain
no flags
Patch (21.13 KB, patch)
2012-04-29 00:47 PDT, Benjamin Poulain
no flags
Patch (24.65 KB, patch)
2012-04-29 01:51 PDT, Benjamin Poulain
darin: review+
Benjamin Poulain
Comment 1 2012-04-29 00:22:17 PDT
Gustavo Noronha (kov)
Comment 2 2012-04-29 00:30:14 PDT
Build Bot
Comment 3 2012-04-29 00:37:27 PDT
Early Warning System Bot
Comment 4 2012-04-29 00:38:39 PDT
Early Warning System Bot
Comment 5 2012-04-29 00:40:05 PDT
Benjamin Poulain
Comment 6 2012-04-29 00:47:51 PDT
Benjamin Poulain
Comment 7 2012-04-29 01:51:12 PDT
Darin Adler
Comment 8 2012-04-29 10:43:19 PDT
Comment on attachment 139398 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=139398&action=review > Source/WTF/ChangeLog:9 > + a string litteral, a new String was constructed implicitely, allocating litteral -> literal implicitely -> implicitly > Source/WTF/ChangeLog:10 > + a new StringImpl and copying the caracters for the operation. caracters -> characters > Source/WTF/ChangeLog:12 > + This patch adds a version of those methods for single character and single character -> single characters litterals -> literals > Source/WTF/wtf/text/AtomicString.h:87 > + bool startsWith(const char* s, unsigned matchLength, bool caseSensitive = true) const > + { return m_string.startsWith(s, matchLength, caseSensitive); } Is this overload used anywhere? > Source/WTF/wtf/text/AtomicString.h:97 > + bool endsWith(const char* s, unsigned matchLength, bool caseSensitive = true) const > + { return m_string.endsWith(s, matchLength, caseSensitive); } Same question. > Source/WTF/wtf/text/StringImpl.cpp:1118 > + if (length()) > + return this->operator[](0) == character; > + return false; I would write this differently: return m_length && (*this)[0] == character; > Source/WTF/wtf/text/StringImpl.cpp:1143 > + if (length()) > + return this->operator[](length() - 1) == character; > + return false; I would write this differently: return m_length && (*this)[m_length - 1] == character; > Source/WTF/wtf/text/StringImpl.cpp:1153 > + ASSERT(matchLength); > + if (matchLength > length()) > + return false; > + unsigned startOffset = length() - matchLength; > + > + return equalInner(this, startOffset, matchString, matchLength, caseSensitive); The paragraphing here seems strange. I’d leave out the blank line.
Benjamin Poulain
Comment 9 2012-04-29 12:36:22 PDT
Thanks for the review. I should use a spellchecker for my change logs... > > Source/WTF/wtf/text/AtomicString.h:87 > > + bool startsWith(const char* s, unsigned matchLength, bool caseSensitive = true) const > > + { return m_string.startsWith(s, matchLength, caseSensitive); } > > Is this overload used anywhere? > > > Source/WTF/wtf/text/AtomicString.h:97 > > + bool endsWith(const char* s, unsigned matchLength, bool caseSensitive = true) const > > + { return m_string.endsWith(s, matchLength, caseSensitive); } > > Same question. They are not, I just figured that could be useful in the future.
Benjamin Poulain
Comment 10 2012-04-30 14:32:01 PDT
Note You need to log in before you can comment on or make changes to this bug.