Example #1
0
static void test_StrRChrA(void)
{
  char string[129];
  WORD count;

  /* this test crashes on win2k SP4 */
  /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/

  for (count = 32; count < 128; count++)
    string[count] = (char)count;
  string[128] = '\0';

  for (count = 32; count < 128; count++)
  {
    LPSTR result = StrRChrA(string+32, NULL, count);
    ok(result - string == count, "found char %d in wrong place\n", count);
  }

  for (count = 32; count < 128; count++)
  {
    LPSTR result = StrRChrA(string+count+1, NULL, count);
    ok(!result, "found char not in the string\n");
  }

  for (count = 32; count < 128; count++)
  {
    LPSTR result = StrRChrA(string+count+1, string + 127, count);
    ok(!result, "found char not in the string\n");
  }
}
Example #2
0
// 最終行を1行またはNULを含む最大textMax(>0)バイト(収まらない場合行頭側をカット)読み込む
// 改行文字は取り除く
// ファイルポインタは先頭に戻る
// 戻り値はNULを含む読み込まれたバイト数
int CTextFileReader::ReadLastLine(char *text, int textMax)
{
	if (!IsOpen()) {
		return 0;
	}
	// 2GB以上には対応しない
	DWORD fileSize = GetFileSize(hFile_, NULL);
	if (fileSize > 0x7FFFFFFF ||
	    SetFilePointer(hFile_, -min(textMax - 1, static_cast<int>(fileSize)), NULL, FILE_END) == INVALID_SET_FILE_POINTER) {
		return 0;
	}
	DWORD read;
	if (!ReadFile(hFile_, text, textMax - 1, &read, NULL)) {
		ResetPointer();
		return 0;
	}
	text[read] = '\0';
	int textLen = lstrlenA(text);
	if (textLen >= 1 && text[textLen-1] == '\n') {
		text[--textLen] = '\0';
	}
	if (textLen >= 1 && text[textLen-1] == '\r') {
		text[--textLen] = '\0';
	}
	char *p = StrRChrA(text, text + textLen, '\n');
	if (p) {
		++p;
		memmove(text, p, textLen - static_cast<int>(p - text) + 1);
		textLen -= static_cast<int>(p - text);
	}
	ResetPointer();
	return textLen + 1;
}