Exemplo n.º 1
0
void ScrSys_LoadPreferences()
{
FILE *fl = fopen(pref_FileName,"rb");
if (fl == NULL)
    return;

char buffer[128];
char *str;

while(!feof(fl))
{
    fgets(buffer,128,fl);
    str=TrimLeft(TrimRight(buffer));
    if (str != NULL)
    if (strlen(str)>0)
        for (int16_t i=0; i<pref_COUNT; i++ )
            if (strCMP(str,prefs[i].name)==0)
            {
                str=strstr(str,"=");
                if (str != NULL)
                {
                    str++;
                    str=TrimLeft(str);
                    SetDirectgVarInt(prefs[i].slot,atoi(str));
                }
                break;
            }
};

fclose(fl);
}
Exemplo n.º 2
0
void SMLoader::LoadFromSMTokens( 
	CString sStepsType, 
	CString sDescription,
	CString sDifficulty,
	CString sMeter,
	CString sRadarValues,
	CString sNoteData,
	CString sAttackData,
	Steps &out
)
{
	TrimLeft(sStepsType); 
	TrimRight(sStepsType); 
	TrimLeft(sDescription); 
	TrimRight(sDescription); 
	TrimLeft(sDifficulty); 
	TrimRight(sDifficulty); 


//	LOG->Trace( "Steps::LoadFromSMTokens()" );

	out.m_StepsType = GameManager::StringToStepsType(sStepsType);
	out.SetDescription(sDescription);
	out.SetDifficulty(StringToDifficulty( sDifficulty ));

	// HACK:  We used to store SMANIAC as DIFFICULTY_HARD with special description.
	// Now, it has its own DIFFICULTY_CHALLENGE
	if( sDescription.CompareNoCase("smaniac") == 0 ) 
		out.SetDifficulty( DIFFICULTY_CHALLENGE );
	// HACK:  We used to store CHALLENGE as DIFFICULTY_HARD with special description.
	// Now, it has its own DIFFICULTY_CHALLENGE
	if( sDescription.CompareNoCase("challenge") == 0 ) 
		out.SetDifficulty( DIFFICULTY_CHALLENGE );

	out.SetMeter(atoi(sMeter));
	CStringArray saValues;
	split( sRadarValues, ",", saValues, true );
	if( saValues.size() == NUM_RADAR_CATEGORIES )
	{
		RadarValues v;
		FOREACH_RadarCategory(rc)
			v[rc] = strtof( saValues[rc], NULL );
		out.SetRadarValues( v ); 
	}
    
	out.SetSMNoteData(sNoteData, sAttackData);

	out.TidyUpData();
}
Exemplo n.º 3
0
/* "path(mangled name+offset) [address]" */
void BacktraceNames::FromString( CString s )
{
    /* Hacky parser.  I don't want to use regexes in the crash handler. */
    CString MangledAndOffset, sAddress;
    unsigned pos = 0;
    while( pos < s.size() && s[pos] != '(' && s[pos] != '[' )
        File += s[pos++];
    TrimRight( File );
    TrimLeft( File );

    if( pos < s.size() && s[pos] == '(' )
    {
        pos++;
        while( pos < s.size() && s[pos] != ')' )
            MangledAndOffset += s[pos++];
    }

    if( MangledAndOffset != "" )
    {
        size_t plus = MangledAndOffset.rfind('+');

        if(plus == MangledAndOffset.npos)
        {
            Symbol = MangledAndOffset;
            Offset = 0;
        }
        else
        {
            Symbol = MangledAndOffset.substr(0, plus);
            CString str = MangledAndOffset.substr(plus);
            if( sscanf(str, "%i", &Offset) != 1 )
                Offset=0;
        }
    }
}
Exemplo n.º 4
0
void ActiveAttackList::Refresh()
{
	CString s;

	const AttackArray& attacks = GAMESTATE->m_ActiveAttacks[m_PlayerNumber];	// NUM_INVENTORY_SLOTS
	
	// clear all lines, then add all active attacks
	for( unsigned i=0; i<attacks.size(); i++ )
	{
		if( !attacks[i].bOn )
			continue; /* hasn't started yet */

		CStringArray asMods;
		split( attacks[i].sModifier, ",", asMods );
		for( unsigned j=0; j<asMods.size(); j++ )
		{
			CString& sMod = asMods[j];
			TrimLeft( sMod );
			TrimRight( sMod );

			sMod = PlayerOptions::ThemeMod( sMod );

			if( s.empty() )
				s = sMod;
			else
				s = sMod + "\n" + s;
		}
	}

	this->SetText( s );	// BitmapText will not rebuild vertices if these strings are the same.
}
Exemplo n.º 5
0
/*----------------------------------------------------------------------
|   NPT_String::Trim
+---------------------------------------------------------------------*/
const NPT_String& 
NPT_String::Trim(char c)
{
    char s[2] = {c, 0};
    TrimLeft((const char*)s);
    return TrimRight((const char*)s);
}
Exemplo n.º 6
0
static TCHAR *
import_label(const char *src)
{
  if (src == nullptr)
    return nullptr;

  src = TrimLeft(src);
  if (strcmp(src, "RAILWAY STATION") == 0 ||
      strcmp(src, "RAILROAD STATION") == 0 ||
      strcmp(src, "UNK") == 0)
    return nullptr;

#ifdef _UNICODE
  size_t length = strlen(src);
  TCHAR *dest = new TCHAR[length + 1];
  if (::MultiByteToWideChar(CP_UTF8, 0, src, -1, dest, length + 1) <= 0) {
    delete[] dest;
    return nullptr;
  }

  return dest;
#else
  if (!ValidateUTF8(src))
    return nullptr;

  return strdup(src);
#endif
}
Exemplo n.º 7
0
	std::string& Trim(std::string& _rString)
	{
		TrimRight(_rString);
		TrimLeft(_rString);

		return (_rString);
	}
Exemplo n.º 8
0
/*----------------------------------------------------------------------
|   NPT_String::Trim
+---------------------------------------------------------------------*/
void 
NPT_String::Trim(char c)
{
    char s[2] = {c, 0};
    TrimLeft((const char*)s);
    TrimRight((const char*)s);
}
Exemplo n.º 9
0
Arquivo: Util.c Projeto: k2b3d/authsrc
char* Trim(char* pszSource)
{
	if (pszSource == NULL) {
		return NULL;
	}
	return TrimLeft(TrimRight(pszSource));
}
Exemplo n.º 10
0
RageLog::~RageLog()
{
	/* Add the mapped log data to info.txt. */
	const CString AdditionalLog = GetAdditionalLog();
	vector<CString> AdditionalLogLines;
	split( AdditionalLog, "\n", AdditionalLogLines );
	for( unsigned i = 0; i < AdditionalLogLines.size(); ++i )
	{
		TrimLeft( AdditionalLogLines[i] );
		TrimRight( AdditionalLogLines[i] );
		this->Info( "%s", AdditionalLogLines[i].c_str() );
	}

	Flush();
	SetShowLogOutput( false );
	g_fileLog->Close();
	g_fileInfo->Close();

	delete g_Mutex;
	g_Mutex = NULL;

	delete g_fileLog;
	g_fileLog = NULL;
	delete g_fileInfo;
	g_fileInfo = NULL;
}
Exemplo n.º 11
0
//---------------------------------------------------------------------------
void TFileMasks::TrimEx(UnicodeString & Str, intptr_t & Start, intptr_t & End)
{
  UnicodeString Buf = TrimLeft(Str);
  Start += Str.Length() - Buf.Length();
  Str = TrimRight(Buf);
  End -= Buf.Length() - Str.Length();
}
Exemplo n.º 12
0
int  CFunc::TrimAll(char *Src)
{
	char *Pt;
	char *pHead = Src;
	TrimLeft(Src);//去除Src左边与右边的空格
	TrimRight(Src);
	
    if((Pt=pHead=strstr(Src," "))==0)
		return 1;
	while(*pHead != '\x0a')
	{
		while ( *pHead == ' ' && *pHead != '\0')
		{
			pHead ++ ;
		}
		while (*pHead != '\0'  && *pHead != ' '&& *pHead!='\x0a')
		{
			*Pt = *pHead ;
			Pt++ ;
			pHead++ ;
		}
		*Pt = '\0' ;
	}
	if((Pt=strstr(Src,";"))!=0)  //去处Src中的注释
	{
		*Pt='\0';
	}
	return 1;
}
Exemplo n.º 13
0
bool XIsEmptyString( const char* str )
{
	CString s(str);
	TrimLeft( s );
	TrimRight( s );

	return ( s.empty() || s == "" );
}
Exemplo n.º 14
0
//---------------------------------------------------------------------------
void __fastcall UncenterButtonImage(TButton * Button)
{
  Button->ImageMargins->Left = 0;
  if (UseThemes())
  {
    Button->Caption = TrimLeft(Button->Caption);
  }
}
Exemplo n.º 15
0
void CUnicodeString::TrimLeft(CHAR chTarget)
{
	CHAR c[] = "\0\0";
	c[0] = chTarget;
	WCHAR wc[] = L"\0\0";;
	MultiByteToWideChar(CP_ACP, 0, c, 1, wc, 1);
	TrimLeft(wc);
}
Exemplo n.º 16
0
/* function name: TrimStr
 * function parameter :
 * 	cpString: any strings
 * function description: remove the string at the beginning of the blank character 
 *      and remove the string at the end of the blank character(去掉字符串开头和末尾的空白字符)
 * returned value: the pointer to the string  
 */
static char *TrimStr(char *cpString)
{
	char *cpRet = NULL;
	
	TrimRight(cpString);
	cpRet = TrimLeft(cpString);
	
	return cpRet;
}
Exemplo n.º 17
0
LISTCHAR* AddToken(LISTCHAR* pListToken, char* strToken)
{
	char* strNewToken = TrimLeft(strToken);
	TrimRight(strNewToken);
	if (strNewToken && strNewToken[0])
		return ListChar_Add(pListToken, strNewToken);
	else
		return pListToken;
}
Exemplo n.º 18
0
/* function name: ParseLine
 * function parameter :
 * 	cpLine: any strings of any lines
 *	cpParam: The specified parameter name
 *	cpValue:The specified parameter value
 * function description: From the value of parameter specifies the parameter name string in a given string line
 	(从给定行字符串中解析出指定参数名的参数值)
 * returned value: the pointer to the specified parameter value  
 */
static char *ParseLine(char *cpLine, char *cpParam, char *cpValue)
{
	char *cpTmp = NULL;
	char *cpPtr = NULL;
	unsigned long ulSepLoc = 0;
	
	/*去掉行首的空格*/
	cpTmp = TrimLeft(cpLine);
	
	/*过滤注释行,即以 # 开头的行, 第一个字符不可以是 = */
	if('#' == *cpTmp || '=' == *cpTmp)
	{
		return NULL;
	}
	
	/*查找 # 号,移除行末注释*/
	ulSepLoc = 0;
	while(ulSepLoc < strlen(cpTmp))
	{
		if('#' == cpTmp[ulSepLoc])
		{
			break;
		}
		ulSepLoc++;
	}
	cpTmp[ulSepLoc] = '\0';
	
	/*查找 = */
	ulSepLoc = 0;
	while(ulSepLoc < strlen(cpTmp))
	{
		if('=' == cpTmp[ulSepLoc])
		{
			break;
		}
		ulSepLoc++;
	}
	if(ulSepLoc == strlen(cpTmp))
	{
		return NULL;
	}
	
	/*获取参数*/
	cpTmp[ulSepLoc] = '\0'; 
	cpPtr = TrimStr(cpTmp);
	if(strcmp(cpPtr, cpParam))
	{
		return NULL;
	}
	
	/*获取参数的值*/
	cpPtr = TrimStr(cpTmp + ulSepLoc + 1);
	strcpy(cpValue, cpPtr);
	
	return cpValue;
}
Exemplo n.º 19
0
void CUnicodeString::TrimLeft(LPCSTR lpszTargets)
{
	ASSERT(IsValidString(lpszTargets));
	DWORD dwszLen = strlen(lpszTargets);
	LPWSTR lpwsz = (LPWSTR)malloc((dwszLen + 1) * sizeof(WCHAR));
	lpwsz[dwszLen] = L'\0';
	MultiByteToWideChar(CP_ACP, 0, lpszTargets, dwszLen, lpwsz, dwszLen);
	TrimLeft(lpwsz);
	free(lpwsz);
}
Exemplo n.º 20
0
/* Trim the string from from spaces from left. */
INDEX CTString::TrimSpacesLeft(void)
{
  // for each character in string
  const char *chr;
  for(chr = str_String; *chr!=0; chr++) {
    // if the character is not space 
    if (!IsSpace(*chr)) {
      // stop searching
      break;
    }
  }
  // trim to that character
  return TrimLeft(str_String+strlen(str_String) - chr);
}
Exemplo n.º 21
0
// 文字列の左右の空白を削除
void Trim(char *str)
{
	// 引数チェック
	if (str == NULL)
	{
		return;
	}

	// 左側を trim
	TrimLeft(str);

	// 右側を trim
	TrimRight(str);
}
Exemplo n.º 22
0
bool GetLemmaFromTitle (string S, long PlaceNo, string& Lemma)
{
	EngRusMakeUpper(S);
	for (size_t i=0; i< PlaceNo + 1; i++)
	{
		int u = S.find_first_of(" ");
		Lemma = S.substr (0, u);
		if (Lemma.empty())  return false;
		S.erase(0,Lemma.length());
		TrimLeft(S);
		
	};
	return true;
};
Exemplo n.º 23
0
int main(int argc, char *argv[])
{
  if (argc != 2) {
    cerr << "Usage: " << argv[0] << " string-to-trim" << endl;
    exit(1);
  }

  StringX s(argv[1]), sl(argv[1]), sr(argv[1]);
  Trim(s); TrimLeft(sl); TrimRight(sr);
  cout << "Trim(\"" << argv[1] << "\") = \"" << s <<"\"" << endl;
  cout << "TrimLeft(\"" << argv[1] << "\") = \"" << sl <<"\"" << endl;
  cout << "TrimRight(\"" << argv[1] << "\") = \"" << sr <<"\"" << endl;
  return 0;
}
Exemplo n.º 24
0
// Remove white spaces of the both side of the string
void Trim(char *str)
{
	// Validate arguments
	if (str == NULL)
	{
		return;
	}

	// Trim on the left side
	TrimLeft(str);

	// Trim on the right side
	TrimRight(str);
}
Exemplo n.º 25
0
Rlist *RlistParseString(char *string, int *n)
{
    Rlist *newlist = NULL;

    char *l = TrimLeft(string);
    if (l == NULL)
    {
        return NULL;
    }
    char *r = TrimRight(l);
    if (r == NULL)
    {
        return NULL;
    }
    newlist = RlistParseStringBounded(l, r, n);
    return newlist;
}
Exemplo n.º 26
0
/////////////////////////////////////////////////////////////////////////////
// GetField()
// Return requested field as a double (function return value) or as a text
// string (*pstr) in the units requested (eUnit). Set 'bStrUnits' to true 
// to have units appended to text string.
//
// Note: numeric return values are cached; asking for the same field more
// than once incurs minimal overhead.
double cTle::GetField(eField   fld, 
                      eUnits   units,    /* = U_NATIVE */
                      string  *pstr      /* = NULL     */,
                      bool     bStrUnits /* = false    */) const
{
   assert((FLD_FIRST <= fld) && (fld < FLD_LAST));
   assert((U_FIRST <= units) && (units < U_LAST));

   if (pstr)
   {
      // Return requested field in string form.
      *pstr = m_Field[fld];
      
      if (bStrUnits)
      {
         *pstr += GetUnits(fld);
      }

      TrimLeft (*pstr);
      TrimRight(*pstr);
      
      return 0.0;
   }
   else
   {
      // Return requested field in floating-point form.
      // Return cache contents if it exists, else populate cache
      FldKey key = Key(units, fld);

      if (m_mapCache.find(key) == m_mapCache.end())
      {
         // Value not in cache; add it
         double valNative = atof(m_Field[fld].c_str());
         double valConv   = ConvertUnits(valNative, fld, units); 
         m_mapCache[key]  = valConv;

         return valConv;
      }
      else
      {
         // return cached value
         return m_mapCache[key];
      }
   }
}
Exemplo n.º 27
0
/////////////////////////////////////////////////////////////////////////////
// ExpToAtof()
// Converts TLE-style exponential notation of the form [ |-]00000[ |+|-]0 to a
// form that is parse-able by the C-runtime function atof(). Assumes implied
// decimal point to the left of the first number in the string, i.e., 
//       " 12345-3" =  0.12345e-3
//       "-23429-5" = -0.23429e-5
//       " 40436+1" =  0.40436e+1
// Assumes that lack of a sign character implies a positive value, i.e.,
//       " 00000 0" =  0.00000
//       " 31415 1" =  3.1415
string cTle::ExpToAtof(const string &str)
{
   const int COL_SIGN     = 0;
   const int LEN_SIGN     = 1;

   const int COL_MANTISSA = 1;
   const int LEN_MANTISSA = 5;

   const int COL_EXPONENT = 6;
   const int LEN_EXPONENT = 2;

   string sign     = str.substr(COL_SIGN,     LEN_SIGN);
   string mantissa = str.substr(COL_MANTISSA, LEN_MANTISSA);
   string exponent = str.substr(COL_EXPONENT, LEN_EXPONENT);

   TrimLeft(exponent);

   return sign + "0." + mantissa + "e" + exponent;
}
Exemplo n.º 28
0
/////////////////////////////////////////////////////////////////////////////
// Returns true if "str" is a valid line of a two-line element set,
// else false.
//
// A valid satellite name is less than or equal to TLE_LEN_LINE_NAME
//      characters;
// A valid data line must:
//      Have as the first character the line number
//      Have as the second character a blank
//      Be TLE_LEN_LINE_DATA characters long
//
bool cTle::IsValidLine(string& str, eTleLine line)
{
   TrimLeft(str);
   TrimRight(str);

   size_t nLen = str.size();

   if (line == LINE_ZERO)
   {
      // Satellite name
      return nLen <= TLE_LEN_LINE_NAME;
   }
   else
   {
      // Data line
      return (nLen == TLE_LEN_LINE_DATA) &&
             ((str[0] - '0') == line)    &&
             (str[1] == ' ');
   }
}
Exemplo n.º 29
0
String CleanTp(const String& tp)
{
	int q = tp.Find('<');
	int w = tp.ReverseFind('>');
	if(q < 0 || w < 0) return tp;
	String a = TrimLeft(TrimRight(tp.Mid(q + 1, w - q - 1)));
	const char *s = a;
	String r;
	while(*s) {
		if(*s == ',') {
			r.Cat(';');
			s++;
			while(*s == ' ')
				s++;
		}
		else
			r.Cat(*s++);
	}
	return r;
}
Exemplo n.º 30
0
bool
ParseFileRepository(FileRepository &repository, NLineReader &reader)
{
  AvailableFile file;
  file.Clear();

  char *line;
  while ((line = reader.ReadLine()) != NULL) {
    line = const_cast<char *>(TrimLeft(line));
    if (*line == 0 || *line == '#')
      continue;

    const char *name = line, *value = ParseLine(line);
    if (value == NULL)
      return false;

    if (StringIsEqual(name, "name")) {
      if (!Commit(repository, file))
        return false;

      file.name.assign(value);
    } else if (file.IsEmpty()) {
      /* ignore */
    } else if (StringIsEqual(name, "uri")) {
      file.uri.assign(value);
    } else if (StringIsEqual(name, "area")) {
      file.area = value;
    } else if (StringIsEqual(name, "type")) {
      if (StringIsEqual(value, "airspace"))
        file.type = AvailableFile::Type::AIRSPACE;
      else if (StringIsEqual(value, "waypoint"))
        file.type = AvailableFile::Type::WAYPOINT;
      else if (StringIsEqual(value, "map"))
        file.type = AvailableFile::Type::MAP;
      else if (StringIsEqual(value, "flarmnet"))
        file.type = AvailableFile::Type::FLARMNET;
    }
  }

  return Commit(repository, file);
}