зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1695817 - Part 1: Make nt::GetLeafName accept nsAString r=mhowell
Differential Revision: https://phabricator.services.mozilla.com/D109302
This commit is contained in:
Родитель
92a4b12566
Коммит
82431c81c9
|
@ -471,11 +471,20 @@ inline void GetLeafName(PUNICODE_STRING aDestString,
|
|||
|
||||
#if defined(MOZILLA_INTERNAL_API)
|
||||
|
||||
inline const nsDependentSubstring GetLeafName(const nsString& aString) {
|
||||
int32_t lastBackslashPos = aString.RFindChar(L'\\');
|
||||
int32_t leafStartPos =
|
||||
(lastBackslashPos == kNotFound) ? 0 : (lastBackslashPos + 1);
|
||||
return Substring(aString, leafStartPos);
|
||||
inline const nsDependentSubstring GetLeafName(const nsAString& aString) {
|
||||
auto it = aString.EndReading();
|
||||
size_t pos = aString.Length();
|
||||
while (it > aString.BeginReading()) {
|
||||
if (*(it - 1) == u'\\') {
|
||||
return Substring(aString, pos);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(pos > 0);
|
||||
--pos;
|
||||
--it;
|
||||
}
|
||||
|
||||
return Substring(aString, 0); // No backslash in the string
|
||||
}
|
||||
|
||||
#endif // defined(MOZILLA_INTERNAL_API)
|
||||
|
|
|
@ -25,3 +25,39 @@ TEST(TestNativeNtGTest, GenerateDependentModuleSet)
|
|||
EXPECT_TRUE(dependentModules.Contains(u"MOZGLUE.dll"_ns));
|
||||
EXPECT_FALSE(dependentModules.Contains(u"xxx.dll"_ns));
|
||||
}
|
||||
|
||||
TEST(TestNativeNtGTest, GetLeafName)
|
||||
{
|
||||
nsAutoString str;
|
||||
str = mozilla::nt::GetLeafName(u""_ns);
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(u"\\"_ns);
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(u"\\\\"_ns);
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(u"abc\\def\\ghi"_ns);
|
||||
EXPECT_STREQ(str.get(), L"ghi");
|
||||
str = mozilla::nt::GetLeafName(u"abcdef"_ns);
|
||||
EXPECT_STREQ(str.get(), L"abcdef");
|
||||
str = mozilla::nt::GetLeafName(u"\\abcdef"_ns);
|
||||
EXPECT_STREQ(str.get(), L"abcdef");
|
||||
|
||||
const auto kEntireText =
|
||||
u"\\"_ns
|
||||
u"\\\\abc"_ns
|
||||
u"\\x\\y\\z"_ns
|
||||
u"123\\456\\"_ns
|
||||
u"789"_ns;
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 0, 0));
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 0, 1));
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 1, 5));
|
||||
EXPECT_STREQ(str.get(), L"abc");
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 6, 6));
|
||||
EXPECT_STREQ(str.get(), L"z");
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 12, 8));
|
||||
EXPECT_STREQ(str.get(), L"");
|
||||
str = mozilla::nt::GetLeafName(Substring(kEntireText, 20));
|
||||
EXPECT_STREQ(str.get(), L"789");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче