Esempio n. 1
0
static size_t cmd_param_len(LPCTSTR lpParam)
{
	int nBacket = 0;
	TCHAR c;

	LPCTSTR lpStr = lpParam;
	while ( (c = *lpStr) != 0 )
	{
		if ( is_blank_char(c) && (nBacket == 0 || nBacket == 2) )
		{
			break;
		}

		lpStr++;
		if ( c == _T('\"') )
		{
			nBacket++;
		}
		else if ( c == _T('\\') )
		{
			// 转义
			if ( lpStr[1] == 0 )
			{
				break;
			}

			lpStr++;
		}
	}

	return (lpStr - lpParam);
}
Esempio n. 2
0
static inline LPCTSTR skip_no_blank(LPCTSTR lpStr)
{
	TCHAR c;
	while ( (c = *lpStr) != 0 )
	{
		if ( is_blank_char(c) )
		{
			return lpStr;
		}
		
		lpStr++;
	}
	
	return lpStr;
}
Esempio n. 3
0
int myAtoi(char *str) {

  int ans = 0;
  boolean check_blank = TRUE;
  boolean check_sign = TRUE;
  boolean negative = FALSE;
  boolean overflow = FALSE;

  int i = 0;

  while (*str != '\0') {
    if (check_blank) {
      if (!is_blank_char(*str)) {
        check_blank = FALSE;
        continue;
      }
    }
    else if (check_sign) {
      if (*str == '+') {
        check_sign = FALSE;
        str++;
        i++;
      }
      else if (*str == '-') {
        negative = TRUE;
        check_sign = FALSE;
        str++;
        i++;
      }
      else {
        check_sign = FALSE;
      }
      continue;
    }
    else {
      char num = is_number(*str);

      printf("  num %d\n", num);

      if (num == -1) {
        break;
      }
      else {
        int new_ans_multiply = ans * 10;
        if (new_ans_multiply / 10 != ans) {
          overflow = TRUE;
        }
        int new_ans_sum = new_ans_multiply + num;
        if (new_ans_sum < new_ans_multiply) {
          overflow = TRUE;
        }
        ans = new_ans_sum;
      }
    }
    str++; 
    i++;
  }

  if (negative) {
    ans = -ans;
    if (overflow) {
      ans = 0x80000000;
    }
  }
  else {
    if (overflow) {
      ans = 0x7FFFFFFF;
    }
  }

  return ans;
}