Example #1
0
int AutoCompData::BuildMemberList( const wxString& name, wxString& list ) const
{
   // First find the object...
   const AutoCompClass* found = FindClassOrObject( name );
   if ( !found )
      return 0;

   // TODO: Should we add members of dupes?

   // Now loop till we run out of base classes.
   wxArrayString tempArray;
   wxString temp;
   size_t len = 0;
   while ( found )
   {
      for ( int i=0; i < found->GetFunctions().GetCount(); i++ ) 
      {
         temp = found->GetFunctions()[i]->GetMethodName() + IDENT_FUNCTION;
         len += temp.Len() + 1;
         tempArray.Add( temp );
      }

      for ( int i=0; i < found->GetVars().GetCount(); i++ ) 
      {
         temp = found->GetVars()[i]->GetName() + IDENT_VAR;
         len += temp.Len() + 1;
         tempArray.Add( temp );
      }

      const wxString& base = found->GetBase();
      if ( base.IsEmpty() )
         break;

      found = FindClassOrObject( base );
   }

   wxString last, member;
   tempArray.Sort( CmpStringNoCase );
   list.Alloc( len - 1 );
   for ( int i=0; i < tempArray.GetCount(); i++ ) {
      member = tempArray[i];
      if ( member.CmpNoCase( last ) == 0 )
         continue;
      list.Append( member );
      list.Append( ' ' );
      last = member;
   }
   list.RemoveLast();
   list.Shrink();

   return (int)tempArray.GetCount();
}
bool FileUtils::ReadFileUTF8(const wxFileName &fn, wxString &data)
{
	wxFFile file(fn.GetFullPath().GetData(), wxT("rb"));
	if(file.IsOpened() == false)
	{
		// Nothing to be done
		return false;
	}
	
	if( file.Length() <= 0){
		return false;
	}

	if( file.Length() > 0 ){
		data.Alloc(file.Length());
	}

	//read first two bytes to check if unicode detected
	bool isUnic(false);
	unsigned char bom[2];
	if(file.Length() >= 2){
		if(file.Read(bom, 2) == 2){
			if(bom[0] == 0xFE && bom[1] == 0xFF){
				//UTF16
				isUnic = true;
			}
		}
	}

	size_t len(file.Length());
	wxFileOffset off(0);
	if( isUnic ){
		//seek file to start to read the consumed two bytes
		len -= 2;
		off = 2;
	}

	file.Seek(off);

	char *pdata = new char[len + 1];
	file.Read(pdata, len);
	pdata[len] = 0;

	data = wxString::FromAscii(pdata);
	file.Close();
	delete [] pdata;
    return true;
}