* Replace the truncate_string() helper function with a new, simplified version.
* Remove no longer necessary support functions. * The new version uses a single BString as input/output parameter and only modifies that one by removing non-fitting chars and inserting the ellipsis where appropriate, so avoids copying around bytes/chars/strings in a few places. It uses the new Chars functions of BString so also no need for manual multibyte handling. * Adjusted the BFont and ServerFont usage of truncate_string() which are both simplified by using the single BString. It avoids a lot of temprary allocations and string copying. The char * version of BFont GetTruncatedStrings() now uses the BString version and not the other way around anymore which requires us to allocate temporary BString objects, it's not worse than before though. * This fixes a bunch of problems with the previous functions like always prepending the ellipsis for B_TRUNCATE_BEGINNING, crashing on short enough widths, violating the width in the B_TRUNCATE_END case when the width was short enough, non-optimal truncation in a few cases and sometimes truncation where none would've been needed. Also fixes #4128 which was a symptom of the broken B_TRUNCATE_BEGINNING. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35381 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
/*
|
||||
* Copyright 2005, Stephan Aßmus <[email protected]>. All rights reserved.
|
||||
* Copyright 2010, Michael Lotz <[email protected]>. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* a helper function to truncate strings
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TRUNCATE_STRING_H
|
||||
#define TRUNCATE_STRING_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
// truncated_string
|
||||
void
|
||||
truncate_string(const char* string,
|
||||
uint32 mode, float width, char* result,
|
||||
const float* escapementArray, float fontSize,
|
||||
float ellipsisWidth, int32 length, int32 numChars);
|
||||
void truncate_string(BString& string, uint32 mode, float width,
|
||||
const float* escapementArray, float fontSize, float ellipsisWidth,
|
||||
int32 numChars);
|
||||
|
||||
#endif // STRING_TRUNCATION_H
|
||||
#endif // TRUNCATE_STRING_H
|
||||
|
||||
Reference in New Issue
Block a user