Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a9a993a authored by Michael Wright's avatar Michael Wright
Browse files

Merge commit '8b452b87' into manual_merge_8b452b8

Change-Id: Iacdc2d521f669661b4979c03b0476512abdb37c7
parents a0c90085 8b452b87
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ public:
            bool                startsWith(const String16& prefix) const;
            bool                startsWith(const char16_t* prefix) const;

            bool                contains(const char16_t* chrs) const;

            status_t            makeLower();

            status_t            replaceAll(char16_t replaceThis,
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ size_t strlen16(const char16_t *);
size_t strnlen16(const char16_t *, size_t);
char16_t *strcpy16(char16_t *, const char16_t *);
char16_t *strncpy16(char16_t *, const char16_t *, size_t);
char16_t *strstr16(const char16_t*, const char16_t*);

// Version of comparison that supports embedded nulls.
// This is different than strncmp() because we don't stop
+5 −0
Original line number Diff line number Diff line
@@ -344,6 +344,11 @@ bool String16::startsWith(const char16_t* prefix) const
    return strncmp16(mString, prefix, ps) == 0;
}

bool String16::contains(const char16_t* chrs) const
{
    return strstr16(mString, chrs) != nullptr;
}

status_t String16::makeLower()
{
    const size_t N = size();
+26 −3
Original line number Diff line number Diff line
@@ -222,11 +222,16 @@ int strncmp16(const char16_t *s1, const char16_t *s2, size_t n)
  char16_t ch;
  int d = 0;

  while ( n-- ) {
  if (n == 0) {
    return 0;
  }

  do {
    d = (int)(ch = *s1++) - (int)*s2++;
    if ( d || !ch )
    if ( d || !ch ) {
      break;
    }
  } while (--n);

  return d;
}
@@ -284,6 +289,24 @@ size_t strnlen16(const char16_t *s, size_t maxlen)
  return ss-s;
}

char16_t* strstr16(const char16_t* src, const char16_t* target)
{
    const char16_t needle = *target++;
    if (needle != '\0') {
      do {
        do {
          if (*src == '\0') {
            return nullptr;
          }
        } while (*src++ != needle);
      } while (strcmp16(src, target) != 0);
      src--;
    }

    return (char16_t*)src;
}


int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2)
{
    const char16_t* e1 = s1+n1;
+35 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ protected:

    virtual void TearDown() {
    }

    char16_t const * const kSearchString = u"I am a leaf on the wind.";
};

TEST_F(UnicodeTest, UTF8toUTF16ZeroLength) {
@@ -112,4 +114,37 @@ TEST_F(UnicodeTest, UTF8toUTF16Normal) {
            << "should be NULL terminated";
}

TEST_F(UnicodeTest, strstr16EmptyTarget) {
    EXPECT_EQ(strstr16(kSearchString, u""), kSearchString)
            << "should return the original pointer";
}

TEST_F(UnicodeTest, strstr16SameString) {
    const char16_t* result = strstr16(kSearchString, kSearchString);
    EXPECT_EQ(kSearchString, result)
            << "should return the original pointer";
}

TEST_F(UnicodeTest, strstr16TargetStartOfString) {
    const char16_t* result = strstr16(kSearchString, u"I am");
    EXPECT_EQ(kSearchString, result)
            << "should return the original pointer";
}


TEST_F(UnicodeTest, strstr16TargetEndOfString) {
    const char16_t* result = strstr16(kSearchString, u"wind.");
    EXPECT_EQ(kSearchString+19, result);
}

TEST_F(UnicodeTest, strstr16TargetWithinString) {
    const char16_t* result = strstr16(kSearchString, u"leaf");
    EXPECT_EQ(kSearchString+7, result);
}

TEST_F(UnicodeTest, strstr16TargetNotPresent) {
    const char16_t* result = strstr16(kSearchString, u"soar");
    EXPECT_EQ(nullptr, result);
}

}