From 3c7eaf396cc792b8bea0955301ee11afb5a8bafd Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Tue, 15 Jan 2013 12:56:17 +0100 Subject: [PATCH] Truncate background image name in multibyte-aware way --- src/preferences/backgrounds/BackgroundImage.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/preferences/backgrounds/BackgroundImage.cpp b/src/preferences/backgrounds/BackgroundImage.cpp index a4b41ec0c2..9c55d8cb4c 100644 --- a/src/preferences/backgrounds/BackgroundImage.cpp +++ b/src/preferences/backgrounds/BackgroundImage.cpp @@ -561,16 +561,15 @@ Image::Image(BPath path) fBitmap(NULL), fPath(path) { - const int32 kMaxWidth = 40; + const int32 kMaxNameChars = 40; fName = path.Leaf(); - int extra = fName.Length() - kMaxWidth; + int extra = fName.CountChars() - kMaxNameChars; if (extra > 0) { + BString extension; int offset = fName.FindLast('.'); - if (offset > 0) { - offset++; - fName.Truncate(offset - extra) << B_UTF8_ELLIPSIS; - fName.Append(path.Leaf() + offset); - } + if (offset > 0) + fName.CopyInto(extension, ++offset, -1); + fName.TruncateChars(kMaxNameChars) << B_UTF8_ELLIPSIS << extension; } }