void test_Concatenate_String_SS (  )
{
  STR80 strTest1, strTest2;


  cout << "Testing:" << endl;
  cout << "void Concatenate_String string string"<<endl;

  GetTestString("....Enter a string 1: ",strTest1);
  GetTestString("....Enter a string 2: ",strTest2);

  cout <<"....String 1 before execution:"<<strTest1<<endl;
  cout <<"....String 2 before execution:"<<strTest2<<endl;
  cout << endl;

  String_Concat(strTest1, strTest2);

  cout << endl;
  cout <<"....String 1 after execution:"<<strTest1<<endl;
  cout <<"....String 2 after execution:"<<strTest2<<endl;


  pause_display();

}
Beispiel #2
0
Int Lexer_ParseReal(Lexer lexer, Bool isFirstContentOnLine)
{
	DECLARE_INLINE_STRINGBUILDER(digitBuilder, 256);	// 256 is plenty for most numbers, but it can grow if necessary.
	const Byte *src = lexer->src;
	const Byte *end = lexer->end;
	const Byte *start;
	Byte ch;
	Token token = lexer->token;
	Int integerDigitCount = 0;
	Int fractionalDigitCount = 0;
	const Byte *digits;
	String digitString, suffix;
	const Byte *suffixText;
	Float64 float64;

	UNUSED(isFirstContentOnLine);

	INIT_INLINE_STRINGBUILDER(digitBuilder);

	START_TOKEN(src);

	// Collect integer digits.
	start = src;
	while (src < end && (ch = *src) >= '0' && ch <= '9') {
		src++;
		if (src + 1 < end
			&& ((ch = *src) == '\'' || ch == '\"' || ch == '_')
			&& src[1] >= '0' && src[1] <= '9') {
			if (src > start) {
				StringBuilder_Append(digitBuilder, start, 0, src - start);
			}
			src++;
			start = src;
		}
	}

	// Copy into the digitBuilder whatever integers are left.
	if (src > start) {
		StringBuilder_Append(digitBuilder, start, 0, src - start);
	}

	integerDigitCount = StringBuilder_GetLength(digitBuilder);

	// Collect the decimal point.
	if (src < end && *src == '.') {
		src++;

		// Collect fractional digits.
		while (src < end && (ch = *src) >= '0' && ch <= '9') {
			src++;
			if (src + 1 < end
				&& ((ch = *src) == '\'' || ch == '\"' || ch == '_')
				&& src[1] >= '0' && src[1] <= '9') {
				if (src > start) {
					StringBuilder_Append(digitBuilder, start, 0, src - start);
				}
				src++;
				start = src;
			}
		}

		fractionalDigitCount = StringBuilder_GetLength(digitBuilder) - 1 - integerDigitCount;
	}

	// Finally copy into the digitBuilder whatever's left.
	if (src > start) {
		StringBuilder_Append(digitBuilder, start, 0, src - start);
	}
	lexer->src = src;

	// Make the result C-friendly.
	StringBuilder_AppendByte(digitBuilder, '\0');

	// Extract out the raw text of the number.
	digitString = StringBuilder_ToString(digitBuilder);
	digits = String_GetBytes(digitString);

	// Get any trailing type identifiers.
	suffix = CollectAlphanumericSuffix(lexer);

	// And make sure the result is clean.
	if (!EnsureEndOfNumber(lexer)) {
		token->text = IllegalRealValueMessage;
		return END_TOKEN(TOKEN_ERROR);
	}

	suffixText = String_GetBytes(suffix);
	if (suffixText[0] == '\0') {
		// Real64.
		if (!Real64_TryParse(digitString, &token->data.real64)) {
			token->text = IllegalRealValueMessage;
			return END_TOKEN(TOKEN_ERROR);
		}
		token->text = digitString;
		return END_TOKEN(TOKEN_REAL64);
	}
	else if (suffixText[0] == 'F' || suffixText[0] == 'f') {
		if (suffixText[1] == '\0') {
			// Float64.
			float64 = strtod(digits, NULL);
			token->data.float64 = float64;
			token->text = digitString;
			return END_TOKEN(TOKEN_FLOAT64);
		}
		else goto badSuffix;
	}
	else if (suffixText[0] == 'L' || suffixText[0] == 'l') {
		// 128-bit something-or-other.
		if (suffixText[1] == '\0') {
			// Real128.
			if (!Real128_TryParse(digitString, &token->data.real128)) {
				token->text = IllegalRealValueMessage;
				return END_TOKEN(TOKEN_ERROR);
			}
			token->text = String_Concat(digitString, suffix);
			return END_TOKEN(TOKEN_REAL128);
		}
		else if ((suffixText[1] == 'F' || suffixText[1] == 'f') && suffixText[2] == '\0') {
			// Float128 (not yet supported).
			goto badSuffix;
		}
		else goto badSuffix;
	}
	else if (suffixText[0] == 'H' || suffixText[0] == 'h') {
		// 32-bit something-or-other.
		if (suffixText[1] == '\0') {
			// Real32.
			if (!Real32_TryParse(digitString, &token->data.real32)) {
				token->text = IllegalRealValueMessage;
				return END_TOKEN(TOKEN_ERROR);
			}
			token->text = String_Concat(digitString, suffix);
			return END_TOKEN(TOKEN_REAL32);
		}
		else if ((suffixText[1] == 'F' || suffixText[1] == 'f') && suffixText[2] == '\0') {
			// Float32.
			float64 = strtod(digits, NULL);
			token->data.float32 = (Float32)float64;
			token->text = digitString;
			return END_TOKEN(TOKEN_FLOAT32);
		}
		else goto badSuffix;
	}
	else goto badSuffix;

badSuffix:
	token->text = String_FormatString(IllegalNumericSuffixMessage, suffix);
	return END_TOKEN(TOKEN_ERROR);
}