当前位置: 首页>>代码示例>>C++>>正文


C++ BString::AppendChars方法代码示例

本文整理汇总了C++中BString::AppendChars方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::AppendChars方法的具体用法?C++ BString::AppendChars怎么用?C++ BString::AppendChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BString的用法示例。


在下文中一共展示了BString::AppendChars方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BString

BString
BJson::_ParseString(BString& JSON, int32& pos)
{
	if (JSON[pos] != '"') // Verify we're at the start of a string.
		return BString("");
	pos++;
	
	BString str;
	while (JSON[pos] != '"') {
		if (JSON[pos] == '\\') {
			pos++;
			switch (JSON[pos]) {
			case 'b':
				str += "\b";
				break;

			case 'f':
				str += "\f";
				break;

			case 'n':
				str += "\n";
				break;

			case 'r':
				str += "\r";
				break;

			case 't':
				str += "\t";
				break;

			case 'u': // 4-byte hexadecimal Unicode char (e.g. "\uffff")
			{
				uint intValue;
				BString substr;
				JSON.CopyInto(substr, pos + 1, 4);
				if (sscanf(substr.String(), "%4x", &intValue) != 1)
					return str;
					// We probably hit the end of the string.
					// This probably should be counted as an error,
					// but for now let's soft-fail instead of hard-fail.

				char character[20];
				char* ptr = character;
				BUnicodeChar::ToUTF8(intValue, &ptr);
				str.AppendChars(character, 1);
				pos += 4;
				break;
			}

			default:
				str += JSON[pos];
				break;
			}
		} else
			str += JSON[pos];
		pos++;
	}

	return str;
}
开发者ID:,项目名称:,代码行数:62,代码来源:

示例2:

void
truncate_string(BString& string, uint32 mode, float width,
	const float* escapementArray, float fontSize, float ellipsisWidth,
	int32 charCount)
{
	// add a tiny amount to the width to make floating point inaccuracy
	// not drop chars that would actually fit exactly
	width += 0.00001;

	switch (mode) {
		case B_TRUNCATE_BEGINNING:
		{
			float totalWidth = 0;
			for (int32 i = charCount - 1; i >= 0; i--) {
				float charWidth = escapementArray[i] * fontSize;
				if (totalWidth + charWidth > width) {
					// we need to truncate
					while (totalWidth + ellipsisWidth > width) {
						// remove chars until there's enough space for the
						// ellipsis
						if (++i == charCount) {
							// we've reached the end of the string and still
							// no space, so return an empty string
							string.Truncate(0);
							return;
						}

						totalWidth -= escapementArray[i] * fontSize;
					}

					string.RemoveChars(0, i + 1);
					string.PrependChars(B_UTF8_ELLIPSIS, 1);
					return;
				}

				totalWidth += charWidth;
			}

			break;
		}

		case B_TRUNCATE_END:
		{
			float totalWidth = 0;
			for (int32 i = 0; i < charCount; i++) {
				float charWidth = escapementArray[i] * fontSize;
				if (totalWidth + charWidth > width) {
					// we need to truncate
					while (totalWidth + ellipsisWidth > width) {
						// remove chars until there's enough space for the
						// ellipsis
						if (i-- == 0) {
							// we've reached the start of the string and still
							// no space, so return an empty string
							string.Truncate(0);
							return;
						}

						totalWidth -= escapementArray[i] * fontSize;
					}

					string.RemoveChars(i, charCount - i);
					string.AppendChars(B_UTF8_ELLIPSIS, 1);
					return;
				}

				totalWidth += charWidth;
			}

			break;
		}

		case B_TRUNCATE_MIDDLE:
		case B_TRUNCATE_SMART:
		{
			float leftWidth = 0;
			float rightWidth = 0;
			int32 leftIndex = 0;
			int32 rightIndex = charCount - 1;
			bool left = true;

			for (int32 i = 0; i < charCount; i++) {
				float charWidth
					= escapementArray[left ? leftIndex : rightIndex] * fontSize;

				if (leftWidth + rightWidth + charWidth > width) {
					// we need to truncate
					while (leftWidth + rightWidth + ellipsisWidth > width) {
						// remove chars until there's enough space for the
						// ellipsis
						if (leftIndex == 0 && rightIndex == charCount - 1) {
							// we've reached both ends of the string and still
							// no space, so return an empty string
							string.Truncate(0);
							return;
						}

						if (leftIndex > 0 && (rightIndex == charCount - 1
								|| leftWidth > rightWidth)) {
							// remove char on the left
//.........这里部分代码省略.........
开发者ID:mmanley,项目名称:Antares,代码行数:101,代码来源:InterfaceDefs.cpp


注:本文中的BString::AppendChars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。