Skip to content

Commit 09e89cc

Browse files
committed
Revert "AK: Made Strings reversible"
This reverts commit 26e81ad. We forgot to consider UTF-8 here. String is UTF-8 and we need to be careful about things like this.
1 parent 2d1f3ec commit 09e89cc

File tree

4 files changed

+4
-28
lines changed

4 files changed

+4
-28
lines changed

AK/String.h

100644100755
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ class String {
110110
return m_impl->to_uppercase();
111111
}
112112

113-
String reversed() const
114-
{
115-
if (!m_impl)
116-
return String();
117-
return m_impl->reversed();
118-
}
119-
120113
Vector<String> split_limit(char separator, int limit) const;
121114
Vector<String> split(char separator) const;
122115
String substring(int start, int length) const;
@@ -234,6 +227,7 @@ struct Traits<String> : public GenericTraits<String> {
234227
struct CaseInsensitiveStringTraits : public AK::Traits<String> {
235228
static unsigned hash(const String& s) { return s.impl() ? s.to_lowercase().impl()->hash() : 0; }
236229
static bool equals(const String& a, const String& b) { return a.to_lowercase() == b.to_lowercase(); }
230+
237231
};
238232

239233
inline bool operator<(const char* characters, const String& string)
@@ -270,5 +264,5 @@ inline bool operator<=(const char* characters, const String& string)
270264

271265
}
272266

273-
using AK::CaseInsensitiveStringTraits;
274267
using AK::String;
268+
using AK::CaseInsensitiveStringTraits;

AK/StringImpl.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "kmalloc.h"
55

66
#ifndef __serenity__
7-
# include <new>
7+
#include <new>
88
#endif
99

1010
//#define DEBUG_STRINGIMPL
@@ -172,19 +172,4 @@ void StringImpl::compute_hash() const
172172
m_has_hash = true;
173173
}
174174

175-
NonnullRefPtr<StringImpl> StringImpl::reversed() const
176-
{
177-
if (m_length == 0)
178-
return the_empty_stringimpl();
179-
180-
char* buffer;
181-
const char* pos = &m_inline_buffer[m_length - 1];
182-
auto new_impl = create_uninitialized(m_length, buffer);
183-
184-
for (int i = 0; i < m_length; i++)
185-
buffer[i] = *pos--;
186-
187-
return new_impl;
188-
}
189-
190175
}

AK/StringImpl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <AK/RefCounted.h>
43
#include <AK/RefPtr.h>
4+
#include <AK/RefCounted.h>
55
#include <AK/Types.h>
66
#include <AK/kmalloc.h>
77

@@ -44,8 +44,6 @@ class StringImpl : public RefCounted<StringImpl> {
4444
return m_hash;
4545
}
4646

47-
NonnullRefPtr<StringImpl> reversed() const;
48-
4947
private:
5048
enum ConstructTheEmptyStringImplTag {
5149
ConstructTheEmptyStringImpl

AK/Tests/TestString.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ TEST_CASE(compare)
4141
EXPECT(!("a" >= String("b")));
4242
EXPECT("a" <= String("a"));
4343
EXPECT(!("b" <= String("a")));
44-
EXPECT(!strcmp(test_string.reversed().characters(), "FEDCBA"));
4544
}
4645

4746
TEST_CASE(index_access)

0 commit comments

Comments
 (0)