common.cpp

来自「这是个很好的源代码,有用的」· C++ 代码 · 共 59 行

CPP
59
字号
// ==============================================================
//
//  Copyright (c) 2002-2003 by Alex Vinokur.
//
//  For conditions of distribution and use, see
//  copyright notice in version.h
//
// ==============================================================


// ##############################################################
//
//  SOFTWARE : Turing Machine (C++ Implementation)
//  FILE     : common.cpp
//
//  DESCRIPTION :
//         Common function etc (Implementation)
//
// ##############################################################



// ###############
#include "common.h"


// ==================================
// ---------------------------------
// Is a string an unsigned decimal?
// ---------------------------------
unsigned int is_udec (char * const str_i)
{
  char *p = &str_i[0];
  while (*p) if (!isdigit (*p++)) return 0;
  return str_i[0];
}

// ==================================
// ---------------------------------
// Is a string a signed decimal?
// ---------------------------------
unsigned int is_dec (char * const str_i)
{
  return (is_udec (&str_i[(str_i[0] == '-') || (str_i[0] == '+')]));
}

// ==================================
// ---------------------------------
// Is a string an hexadecimal?
// ---------------------------------
unsigned int is_hex (char * const str_i)
{
  int start_pos = ((str_i[0] == '0') && (str_i[1] == 'x')) ? 2 : 0;
  char *p = &str_i[start_pos];
  while (*p) if (!isxdigit (*p++)) return 0;
  return str_i[start_pos];
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?