Ejemplo n.º 1
0
cTle::cTle(string& strName, string& strLine1, string& strLine2)
{
   m_strLine0  = strName;
   m_strLine1 = strLine1;
   m_strLine2 = strLine2;

   TrimRight(m_strLine0);
   Initialize();
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
    /*********************************************************
    **************************解密函数************************
    **************每输入16个字节密文得到8字节明文*************
    ***************最终只要用这个函数来解密即可***************
    **********************************************************/
    void decodepass(char *key,char *inblock,char * outblock)
    {
        int i,l;
        char *inblocktemp, *outblocktemp,*temp;

        if ( key==NULL || inblock==NULL)
        {
            strcpy(outblock, "");
            return;
        }

        if (strlen(inblock)==0)
        {
            strcpy(outblock, "");
            return;
        }


        l = strlen(key);

        /* key must 8 char */
        if (l>8)
            key[8]='\0';
        if (l<8)
            for (i=8; i>l; i--)
                strcat(key," ");

        /* inblock must 16*n */
        l = strlen(inblock) % 16;

        if (l!=0)
            for (i=16; i>l; i--)
                strcat(inblock," ");

        inblocktemp = (char *) malloc(17);
        outblocktemp = (char *) malloc(9);

        l = strlen(inblock);

        bzero(outblock,strlen(outblock));


        for (i=0; i<l; i+=16)
        {
            temp = &inblock[i];
            strncpy(inblocktemp,temp,16);
            DoDecDES16((A16 *)inblocktemp, key, (A8 *)outblocktemp);
            outblocktemp[8]=0;

            if (i==l-8)
                outblocktemp = TrimRight(outblocktemp);
            strcat(outblock,outblocktemp);
        }
        free(inblocktemp);
        free(outblocktemp);
    }
Ejemplo n.º 4
0
bool Pop3::PutGet(const String& s, bool multiline, bool nolog)
{
	// Put() request.
	if(!s.IsEmpty()) {
		if(!nolog)
			LLOG(">> " << TrimRight(s));
		if(!PutAll(s)) {
			LLOG("-- " << GetLastError());
			return false;
		}		
	}
	// Get() respone.
	data.Clear();
	const int MAXLINE = 20000000;
	String line = GetLine(MAXLINE);
	if(!line.IsVoid()) {
		LLOG("<< " << TrimRight(line));
		if(line.StartsWith("+OK")) {
			if(!multiline) {
				data.Cat(line);
				data.Cat("\r\n");
				return true;
			}
			else 
				for(;;) {
					line = GetLine(MAXLINE);
					if(line.IsVoid())
						break;
					if(line == ".") {
						LLOG("<< ...");
						return true;
					}
					data.Cat(*line == '.' ? line.Mid(1) : line);
					data.Cat("\r\n");
				}
		}
		else
		if(line.StartsWith("-ERR"))
			error = line;
	}
	LLOG("-- " << GetLastError());
	return false;
}
Ejemplo n.º 5
0
void CUnicodeString::TrimRight(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);
	TrimRight(lpwsz);
	free(lpwsz);
}
Ejemplo n.º 6
0
CppItem& Parser::Item(const String& nameing, const String& nesting, const String& item)
{
	CppItem& im = base->GetAdd(nameing).GetAdd(nesting).GetAdd(TrimRight(Purify(item)));
	im.pname.Clear();
	im.param.Clear();
	im.package = package;
	im.file = filename;
	im.line = line + 1;
	im.name.Clear();
	return im;
}
Ejemplo n.º 7
0
static void GetDriveDebugInfoNT()
{
	/*
	 * HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\
	 *    Scsi Port *\
	 *      DMAEnabled  0 or 1
	 *      Driver      "Ultra", "atapi", etc
	 *      Scsi Bus *\
	 *	     Target Id *\
	 *	 	   Logical Unit Id *\
	 *		     Identifier  "WDC WD1200JB-75CRA0"
	 *			 Type        "DiskPeripheral"
	 */
	vector<RString> Ports;
	if( !RegistryAccess::GetRegSubKeys( "HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\Scsi", Ports ) )
		return;

	for( unsigned i = 0; i < Ports.size(); ++i )
	{
		int DMAEnabled = -1;
		RegistryAccess::GetRegValue( Ports[i], "DMAEnabled", DMAEnabled );

		RString Driver;
		RegistryAccess::GetRegValue( Ports[i], "Driver", Driver );

		vector<RString> Busses;
		if( !RegistryAccess::GetRegSubKeys( Ports[i], Busses, "Scsi Bus .*" ) )
			continue;

		for( unsigned bus = 0; bus < Busses.size(); ++bus )
		{
			vector<RString> TargetIDs;
			if( !RegistryAccess::GetRegSubKeys( Busses[bus], TargetIDs, "Target Id .*" ) )
				continue;

			for( unsigned tid = 0; tid < TargetIDs.size(); ++tid )
			{
				vector<RString> LUIDs;
				if( !RegistryAccess::GetRegSubKeys( TargetIDs[tid], LUIDs, "Logical Unit Id .*" ) )
					continue;

				for( unsigned luid = 0; luid < LUIDs.size(); ++luid )
				{
					RString Identifier;
					RegistryAccess::GetRegValue( LUIDs[luid], "Identifier", Identifier );
					TrimRight( Identifier );
					LOG->Info( "Drive: \"%s\" Driver: %s DMA: %s",
						Identifier.c_str(), Driver.c_str(), DMAEnabled == 1? "yes":DMAEnabled == -1? "N/A":"NO" );
				}
			}
		}
	}
}
Ejemplo n.º 8
0
// retain only first line of the string
void CTString::OnlyFirstLine(void)
{
  // get position of first line end
  const char *pchNL = strchr(str_String, '\n');
  // if none
  if (pchNL==NULL) {
    // do nothing
    return;
  }
  // trim everything after that char
  TrimRight(pchNL-str_String);
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
// 文字列の左右の空白を削除
void Trim(char *str)
{
	// 引数チェック
	if (str == NULL)
	{
		return;
	}

	// 左側を trim
	TrimLeft(str);

	// 右側を trim
	TrimRight(str);
}
Ejemplo n.º 11
0
/* Trim the string from from spaces from right. */
INDEX CTString::TrimSpacesRight(void)
{
  // for each character in string reversed
  const char *chr;
  for(chr = str_String+strlen(str_String)-1; chr>str_String; chr--) {
    // if the character is not space 
    if (!IsSpace(*chr)) {
      // stop searching
      break;
    }
  }
  // trim to that character
  return TrimRight(chr-str_String+1);
}
Ejemplo n.º 12
0
void LoadDataToTrie(CDnaTrieBuilder &trieBuilder, const std::string &inputFileName)
{
	static const int c_maxStrLen = 16384;
	FILE *f = stdin;

	if (!inputFileName.empty())
		f = fopen(inputFileName.c_str(), "r");

	char buf[c_maxStrLen];
	std::string str;
	int readStrCount = 0;

	if (!f)
		THROW_EXCEPTION("Couldn't open input file");

	buf[0] = 0;
	while (true)
	{
		FUNC_GUARD

		char *res = fgets(buf, c_maxStrLen, f);

		str = buf;
		TrimRight(str);
		if (!res || str.empty())
		{
			printf("%d lines read\n", readStrCount);
			trieBuilder.PrintCheckSum();
			if (!inputFileName.empty())
				fclose(f);
			return;
		}

		std::string::size_type commaPos = str.rfind(',');
		int count = -1;

		if (commaPos == std::string::npos)
			THROW_EXCEPTION("No comma in input string");
		if (sscanf(str.c_str() + commaPos + 1, "%d", &count) != 1 || count <= 0)
			THROW_EXCEPTION("Invalid DNA count");
	
		str.resize(commaPos);

		trieBuilder.AddDna(str, count);

		readStrCount++;
		if (readStrCount % (1 << 17) == 0)
			printf("%d lines read\n", readStrCount);
	}
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
int SortAsFileSize(LPCWSTR str1, LPCWSTR str2) {
  UINT64 size[2] = {1, 1};

  for (size_t i = 0; i < 2; i++) {
    std::wstring value = i == 0 ? str1 : str2;
    std::wstring unit;

    TrimRight(value, L".\r");
    EraseChars(value, L" ");

    if (value.length() >= 2) {
      for (auto it = value.rbegin(); it != value.rend(); ++it) {
        if (IsNumericChar(*it))
          break;
        unit.insert(unit.begin(), *it);
      }
      value.resize(value.length() - unit.length());
      Trim(unit);
    }

    int index = InStr(value, L".");
    if (index > -1) {
      int length = value.substr(index + 1).length();
      if (length <= 2)
        value.append(2 - length, '0');
      EraseChars(value, L".");
    } else {
      value.append(2, '0');
    }

    if (IsEqual(unit, L"KB")) {
      size[i] *= 1000;
    } else if (IsEqual(unit, L"KiB")) {
      size[i] *= 1024;
    } else if (IsEqual(unit, L"MB")) {
      size[i] *= 1000 * 1000;
    } else if (IsEqual(unit, L"MiB")) {
      size[i] *= 1024 * 1024;
    } else if (IsEqual(unit, L"GB")) {
      size[i] *= 1000 * 1000 * 1000;
    } else if (IsEqual(unit, L"GiB")) {
      size[i] *= 1024 * 1024 * 1024;
    }

    size[i] *= _wtoi(value.c_str());
  }

  return CompareValues<UINT64>(size[0], size[1]);
}
Ejemplo n.º 15
0
int main(int argc, char **argv)
{
  NarrowString<1024> usage;
  usage = "DRIVER\n\n"
          "Where DRIVER is one of:";
  {
    const DeviceRegister *driver;
    for (unsigned i = 0; (driver = GetDriverByIndex(i)) != NULL; ++i) {
      WideToUTF8Converter driver_name(driver->name);
      usage.AppendFormat("\n\t%s", (const char *)driver_name);
    }
  }

  Args args(argc, argv, usage);
  tstring driver_name = args.ExpectNextT();
  args.ExpectEnd();

  driver = FindDriverByName(driver_name.c_str());
  if (driver == NULL) {
    _ftprintf(stderr, _T("No such driver: %s\n"), driver_name.c_str());
    return 1;
  }

  DeviceConfig config;
  config.Clear();

  NullPort port;
  Device *device = driver->CreateOnPort != NULL
    ? driver->CreateOnPort(config, port)
    : NULL;

  NMEAParser parser;

  NMEAInfo data;
  data.Reset();

  char buffer[1024];
  while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
    TrimRight(buffer);

    if (device == NULL || !device->ParseNMEA(buffer, data))
      parser.ParseLine(buffer, data);
  }

  Dump(data);

  return EXIT_SUCCESS;
}
Ejemplo n.º 16
0
static void
LoadSecondaryFile(TLineReader &reader)
{
  TCHAR *line;
  while ((line = reader.read()) != NULL) {
    TCHAR *endptr;
    FlarmId id;
    id.parse(line, &endptr);
    if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) {
      TCHAR *Name = endptr + 1;
      TrimRight(Name);
      if (!FlarmDetails::AddSecondaryItem(id, Name))
        break; // cant add anymore items !
    }
  }
}
Ejemplo n.º 17
0
/*
Filtern einer Zeile:
  - Umwandeln von nicht-IGC-Zeichen in Leerzeichen
  - Entfernen von Leer- und Sonderzeichen am Ende (TrimRight)
*/
char *igc_filter(char *st) {
 static constexpr char alphabet[] =
   " \"#%&\'()+-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_\140abcdefghijklmnopqrstuvwxyz{|}";
 static constexpr int alphabet_l = ARRAY_SIZE(alphabet) - 1;
 int l = strlen(st);
 int i,j;
 int found;
  for(i=0; i<l; i++) {
    found = 0;
    for(j=0; j<alphabet_l; j++)
      if (st[i] == alphabet[j])
	found = 1;
    if (!found) st[i] = ' ';
  }
  TrimRight(st);
  return st;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
static void WriteLineList( RageFile &f, vector<CString> &lines, bool SkipLeadingBlankLines, bool OmitLastNewline )
{
	for( unsigned i = 0; i < lines.size(); ++i )
	{
		TrimRight( lines[i] );
		if( SkipLeadingBlankLines )
		{
			if( lines.size() == 0 )
				continue;
			SkipLeadingBlankLines = false;
		}
		f.Write( lines[i] );

		if( !OmitLastNewline || i+1 < lines.size() )
			f.PutLine( "" ); /* newline */
	}
}
Ejemplo n.º 20
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];
      }
   }
}
Ejemplo n.º 21
0
String Parser::ReadOper() {
	const char *p = lex.Pos();
	const char *p1 = p;
	Key(tk_operator);
	int level = 0;
	if(Key('('))
		level++;
	for(;;) {
		p1 = lex.Pos();
		if(lex == t_eof) break;
		if(level <= 0 && lex == '(') break;
		if(Key('(') || Key('[')) level++;
		else
		if(Key(')')  || Key(']')) level--;
		else
			++lex;
	}
	return TrimRight(Purify(String(p, p1)));
}
Ejemplo n.º 22
0
void
LoadFlarmNameFile(TLineReader &reader, FlarmNameDatabase &db)
{
  TCHAR *line;
  while ((line = reader.ReadLine()) != NULL) {
    TCHAR *endptr;
    FlarmId id = FlarmId::Parse(line, &endptr);
    if (!id.IsDefined())
      /* ignore malformed records */
      continue;

    if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) {
      TCHAR *Name = endptr + 1;
      TrimRight(Name);
      if (!db.Set(id, Name))
        break; // cant add anymore items !
    }
  }
}
Ejemplo n.º 23
0
static void
OnCodeClicked()
{
  TCHAR newTeammateCode[10];

  CopyString(newTeammateCode,
             CommonInterface::GetComputerSettings().team_code.team_code.GetCode(), 10);

  if (!dlgTextEntryShowModal(newTeammateCode, 7))
    return;

  TrimRight(newTeammateCode);

  TeamCodeSettings &settings =
    CommonInterface::SetComputerSettings().team_code;
  settings.team_code.Update(newTeammateCode);
  if (settings.team_code.IsDefined())
    settings.team_flarm_id.Clear();
}
Ejemplo n.º 24
0
void
LogLastError(const TCHAR *fmt, ...)
{
    const DWORD error = GetLastError();

    TCHAR buffer[1024];
    va_list ap;
    va_start(ap, fmt);
    _vsntprintf(buffer, ARRAY_SIZE(buffer), fmt, ap);
    va_end(ap);

    TCHAR msg[256];
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL, error, 0, msg, ARRAY_SIZE(msg), NULL);
    TrimRight(msg);

    LogStartUp(_T("%s: %s"), buffer, msg);
}
Ejemplo n.º 25
0
/**
 * Decodes the FlarmNet.org file and puts the wanted
 * characters into the res pointer
 * @param file File handle
 * @param charCount Number of character to decode
 * @param res Pointer to be written in
 */
static void
LoadString(const char *bytes, size_t length, TCHAR *res, size_t res_size)
{
  const char *const end = bytes + length * 2;

#ifndef _UNICODE
  const char *const limit = res + res_size - 2;
#endif

  TCHAR *p = res;

  char tmp[3];
  tmp[2] = 0;

  while (bytes < end) {
    tmp[0] = *bytes++;
    tmp[1] = *bytes++;

    /* FLARMNet files are ISO-Latin-1, which is kind of short-sighted */

    const unsigned char ch = (unsigned char)strtoul(tmp, NULL, 16);
#ifdef _UNICODE
    /* Latin-1 can be converted to WIN32 wchar_t by casting */
    *p++ = ch;
#else
    /* convert to UTF-8 on all other platforms */

    if (p >= limit)
      break;

    p = Latin1ToUTF8(ch, p);
#endif
  }

  *p = 0;

#ifndef _UNICODE
  assert(ValidateUTF8(res));
#endif

  // Trim the string of any additional spaces
  TrimRight(res);
}
Ejemplo n.º 26
0
CString Font::GetFontName( CString sFileName )
{
	CString sOrig = sFileName;

	CString sDir, sFName, sExt;
	splitpath( sFileName, sDir, sFName, sExt );
	sFileName = sFName;

	/* If it ends in an extension, remove it. */
	static Regex drop_ext( "\\....$" );
	if( drop_ext.Compare(sFileName) )
		sFileName.erase( sFileName.size()-4 );

	/* If it ends in a resolution spec, remove it. */
	CStringArray asMatch;
	static Regex ResSpec( "( \\(res [0-9]+x[0-9]+\\))$" );
	if( ResSpec.Compare(sFileName, asMatch) )
		sFileName.erase(sFileName.size()-asMatch[0].size());

	/* If it ends in a dimension spec, remove it. */
	static Regex DimSpec( "( [0-9]+x[0-9]+)$" );
	if( DimSpec.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in texture hints, remove them. */
	static Regex Hints( "( \\([^\\)]+\\))$" );
	if( Hints.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in a page name, remove it. */
	static Regex PageName("( \\[.+\\])$");
	if( PageName.Compare( sFileName, asMatch ) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	TrimRight( sFileName );

	if( sFileName.empty() )
		RageException::Throw( "Can't parse font filename \"%s\"", sOrig.c_str() );

	sFileName.MakeLower();
	return sFileName;
}
Ejemplo n.º 27
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] == ' ');
   }
}
Ejemplo n.º 28
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;
}
Ejemplo n.º 29
0
RString werr_ssprintf( int err, const char *fmt, ... )
{
	char buf[1024] = "";
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
		0, err, 0, buf, sizeof(buf), NULL);

	// Why is FormatMessage returning text ending with \r\n? (who? -aj)
	// Perhaps it's because you're on Windows, where newlines are \r\n. -aj
	RString text = buf;
	text.Replace( "\n", "" );
	text.Replace( "\r", " " ); // foo\r\nbar -> foo bar
	TrimRight( text ); // "foo\r\n" -> "foo"

	va_list	va;
	va_start(va, fmt);
	RString s = vssprintf( fmt, va );
	va_end(va);

	return s += ssprintf( " (%s)", text.c_str() );
}
Ejemplo n.º 30
0
void MediaPlayers::EditTitle(wstring& str, int player_index) {
    if (str.empty() || items[player_index].edits.empty()) return;

    for (unsigned int i = 0; i < items[player_index].edits.size(); i++) {
        switch (items[player_index].edits[i].mode) {
        // Erase
        case 1: {
            Replace(str, items[player_index].edits[i].value, L"", false, true);
            break;
        }
        // Cut right side
        case 2: {
            int pos = InStr(str, items[player_index].edits[i].value, 0);
            if (pos > -1) str.resize(pos);
            break;
        }
        }
    }

    TrimRight(str, L" -");
}