Exemple #1
0
UTF8String Filename::getDirectory() const
{
	UTF8String::const_reverse_iterator it = std::find_if(this->rbegin(), this->rend(), isPathSeparator);
	if (it!=this->rend())
		return UTF8String(this->begin(), it.base());
	else
		return UTF8String("");
}
Exemple #2
0
UTF8String Filename::getBaseFilename() const
{
	const UTF8String fname = getFilename();
	UTF8String::const_reverse_iterator it = std::find(fname.rbegin(), fname.rend(), '.');
	if (it!=fname.rend())
		return UTF8String(fname.begin(), it.base()-1);
	else
		return UTF8String("");
}
Exemple #3
0
UTF8String Filename::getExtension(bool includeDot) const
{
	const UTF8String fname = getFilename();
	UTF8String::const_reverse_iterator it = std::find(fname.rbegin(), fname.rend(), '.');
	if (it!=fname.rend())
		return UTF8String(it.base() - ((includeDot) ? 1 : 0), fname.end());
	else
		return UTF8String("");
}
void TraceDumpToFile()
{
    if (TraceFile != nullptr)
    {
        TGuard Guard(TracingCriticalSection);

        DWORD Written;

        TDateTime N = Now();
#ifdef TRACE_IN_MEMORY_NO_FORMATTING
        DWORD Ticks = GetTickCount();
#endif

        const UnicodeString TimestampFormat = L"hh:mm:ss.zzz";
        UnicodeString TimeString = FormatDateTime(TimestampFormat, N);

        UTF8String Buffer = UTF8String(
                                FORMAT("[%s] Dumping in-memory tracing =================================\n",
                                       (TimeString)));
        WriteFile(TraceFile, Buffer.c_str(), Buffer.Length(), &Written, nullptr);

        TTracesInMemory::const_iterator i = TracesInMemory.begin();
        while (i != TracesInMemory.end())
        {
#ifdef TRACE_IN_MEMORY_NO_FORMATTING
            const wchar_t * SourceFile = i->SourceFile;
            const wchar_t * Slash = wcsrchr(SourceFile, L'\\');
            if (Slash != nullptr)
            {
                SourceFile = Slash + 1;
            }

            TimeString =
                FormatDateTime(TimestampFormat,
                               IncMilliSecond(N, -static_cast<int>(Ticks - i->Ticks)));
            Buffer = UTF8String(FORMAT(L"[%s] [%.4X] [%s:%d:%s] %s\n",
                                       (TimeString, int(i->Thread), SourceFile,
                                        i->Line, i->Func, i->Message)));
            WriteFile(TraceFile, Buffer.c_str(), Buffer.Length(), &Written, nullptr);
#else
            WriteFile(TraceFile, i->Message.c_str(), i->Message.Length(), &Written, nullptr);
#endif
            ++i;
        }
        TracesInMemory.clear();

        TimeString = FormatDateTime(TimestampFormat, Now());
        Buffer = UTF8String(
                     FORMAT("[%s] Done in-memory tracing =================================\n",
                            (TimeString)));
        WriteFile(TraceFile, Buffer.c_str(), Buffer.Length(), &Written, nullptr);
    }
}
bool RecentFilterInfo::getProperty( const Falcon::String& s, Falcon::Item& it ) const
{
    if ( s == "contains" )
        it = (int64) m_info->contains;
    else
    if ( s == "uri" )
        it = UTF8String( m_info->uri ? m_info->uri : "" );
    else
    if ( s == "display_name" )
        it = UTF8String( m_info->display_name ? m_info->display_name : "" );
    else
    if ( s == "mime_type" )
        it = UTF8String( m_info->mime_type ? m_info->mime_type : "" );
    else
    if ( s == "applications" )
    {
        if ( m_info->applications )
        {
            int cnt = 0;
            gchar* p;
            for ( p = (gchar*) m_info->applications[0]; p; ++p ) ++cnt;
            CoreArray* arr = new CoreArray( cnt );
            for ( p = (gchar*) m_info->applications[0]; p; )
                arr->append( UTF8String( p++ ) );
            it = arr;
        }
        else
            it = new CoreArray( 0 );
    }
    else
    if ( s == "groups" )
    {
        if ( m_info->groups )
        {
            int cnt = 0;
            gchar* p;
            for ( p = (gchar*) m_info->groups[0]; p; ++p ) ++cnt;
            CoreArray* arr = new CoreArray( cnt );
            for ( p = (gchar*) m_info->groups[0]; p; )
                arr->append( UTF8String( p++ ) );
            it = arr;
        }
        else
            it = new CoreArray( 0 );
    }
    else
    if ( s == "age" )
        it = m_info->age;
    else
        return false;
    return true;
}
Exemple #6
0
//---------------------------------------------------------------------------
void __fastcall TForm2::btnGetDeviceInfoClick(TObject *Sender)
{
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
	_di_UIDevice device = TUIDevice::Wrap(TUIDevice::OCClass->currentDevice());
	lbOSName->Text = lbOSName->Text.sprintf(L"OS Name: %s", device->systemName()->UTF8String());
	lbOSVersion->Text = lbOSVersion->Text.sprintf(L"OS Version: %s", device->systemVersion()->UTF8String());
	lbDeviceType->Text = lbDeviceType->Text.sprintf(L"Device Type: %s", device->model()->UTF8String());
#endif
#if defined(__ANDROID__)
  lbDeviceType->Text = String().sprintf(L"Device Type: %s", UTF8String(JStringToString(TJBuild::JavaClass->MODEL)).c_str());
  lbOSName->Text =     String().sprintf(L"OS Name: %s",  UTF8String(GetCodename( JStringToString(TJBuild_VERSION::JavaClass->RELEASE))).c_str());
  lbOSVersion->Text =  String().sprintf(L"OS Version: %s", UTF8String(JStringToString(TJBuild_VERSION::JavaClass->RELEASE)).c_str());
#endif
}
Exemple #7
0
/*#
    @method get_label GtkMenuItem
    @brief Gets the text on the menu_item label
    @return The text in the menu_item label.
 */
FALCON_FUNC MenuItem::get_label( VMARG )
{
    NO_ARGS
    MYSELF;
    GET_OBJ( self );
    vm->retval( UTF8String( gtk_menu_item_get_label( (GtkMenuItem*)_obj ) ) );
}
DWORD HFormatMessage(DWORD inFlags, const char* inSource,
			DWORD inMessageID, DWORD inLanguageID, char* outBuffer,
			int inBufferLength, char** inArguments)
{
	DWORD result;
//	HWFStr dst(outBuffer, static_cast<unsigned int>(inBufferLength));
	HAutoBuf<wchar_t> b(new wchar_t[inBufferLength]);

	UTF16String s(Convert(UTF8String(inSource)));

	//if (HasUnicode())
	result = ::FormatMessageW(inFlags, s.c_str(),
		inMessageID, inLanguageID, b.get(),
		static_cast<unsigned int>(inBufferLength), inArguments);

	UTF8String b2 = Convert(UTF16String(b.get()));
	
	if (b2.length() >= inBufferLength)
		b2.erase(b2.begin() + inBufferLength - 1, b2.end());
			
	b2.copy(outBuffer, inBufferLength - 1);
	outBuffer[b2.length()] = 0;

	//else
	//	result = ::FormatMessageA(inFlags, (char*)HWTStr(inSource),
	//		inMessageID, inLanguageID, (char*)dst,
	//		static_cast<unsigned int>(inBufferLength), inArguments);
	return result;
}
void TSessionLog::DoAddToSelf(TLogLineType Type, UnicodeString ALine)
{
  if (LogToFile()) { try
  {
    if (FLogger == nullptr)
    {
      OpenLogFile();
    }

    if (FLogger != nullptr)
    {
      UnicodeString Timestamp = FormatDateTime(L" yyyy-mm-dd hh:nn:ss.zzz ", Now());
      UTF8String UtfLine = UTF8String(UnicodeString(LogLineMarks[Type]) + Timestamp + TrimRight(ALine)) + "\r\n";
#if 0
      for (intptr_t Index = 1; Index <= UtfLine.Length(); Index++)
      {
        if ((UtfLine[Index] == '\n') &&
            (UtfLine[Index - 1] != '\r'))
        {
          UtfLine.Insert(L'\r', Index);
        }
      }
#endif // #if 0
      intptr_t ToWrite = UtfLine.Length();
      CheckSize(ToWrite);
      FCurrentFileSize += FLogger->Write(UtfLine.c_str(), ToWrite);
    }}
    catch (...)
    {
      // TODO: log error
      DEBUG_PRINTF("TSessionLog::DoAddToSelf: error");
    }
  }
}
Exemple #10
0
//
// _getStringFromTrueTypeFont -- Currently this is a private method
//
UTF8String FontFace::_getStringFromTrueTypeFont(FT_SfntName &fontName) const{
	
	// FOR DEBUGGING:
	//std::cout << "PLATFORM ID  IS " << fontName.platform_id << std::endl;
	//std::cout << "PLATFORM ENC IS " << fontName.encoding_id << std::endl;
	
	if(fontName.platform_id==3 && fontName.encoding_id==1){
		//
		// Windows platform: This is the most commonly encountered situation:
		//
		return _getPlatform3Encoding1String(fontName.string_len,fontName.string);
	}else if(fontName.platform_id==1){
		//
		// For Apple OS X, the encoding_id theoretically 
		// represents different script codes: 0 is for Mac Roman.
		// To the extent tested, this seems to work even for non-zero encoding IDs:
		//
		return _getPlatform1Encoding0String(fontName.string_len,fontName.string);
	}else{
		
		std::ostringstream ss;
		ss << "Unsupported platform (" << fontName.platform_id << ") and id (" << fontName.encoding_id << ")!";
		return UTF8String( ss.str() );
		
	}
}
void CellRendererAccel::on_accel_cleared( GtkCellRendererAccel* obj, gchar* path, gpointer _vm )
{
    GET_SIGNALS( obj );
    CoreSlot* cs = _signals->getChild( "accel_cleared", false );

    if ( !cs || cs->empty() )
        return;

    VMachine* vm = (VMachine*) _vm;
    Iterator iter( cs );
    Item it;

    do
    {
        it = iter.getCurrent();

        if ( !it.isCallable() )
        {
            if ( !it.isComposed()
                || !it.asObject()->getMethod( "on_accel_cleared", it ) )
            {
                printf(
                "[GtkCellRendererAccel::on_accel_cleared] invalid callback (expected callable)\n" );
                return;
            }
        }
        vm->pushParam( UTF8String( path ) );
        vm->callItem( it, 1 );
    }
    while ( iter.hasCurrent() );
}
Exemple #12
0
//---------------------------------------------------------------------------
void TActionLog::Add(const UnicodeString & Line)
{
  assert(FConfiguration);
  if (FLogging)
  {
    try
    {
      TGuard Guard(FCriticalSection);
      if (FFile == nullptr)
      {
        OpenLogFile();
      }

      if (FFile != nullptr)
      {
        UTF8String UtfLine = UTF8String(Line);
        fwrite(UtfLine.c_str(), 1, UtfLine.Length(), (FILE *)FFile);
        fwrite("\n", 1, 1, (FILE *)FFile);
      }
    }
    catch (Exception &E)
    {
      // We failed logging, turn it off and notify user.
      FConfiguration->SetLogActions(false);
      try
      {
        throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
      }
      catch (Exception &E)
      {
        FUI->HandleExtendedException(&E);
      }
    }
  }
}
bool HasGSSAPI(const UnicodeString & CustomPath)
{
  static int has = -1;
  if (has < 0)
  {
    Conf * conf = conf_new();
    ssh_gss_liblist * List = nullptr;
    {
      SCOPE_EXIT
      {
        ssh_gss_cleanup(List);
        conf_free(conf);
      };
      Filename * filename = filename_from_str(UTF8String(CustomPath).c_str());
      conf_set_filename(conf, CONF_ssh_gss_custom, filename);
      filename_free(filename);
      List = ssh_gss_setup(conf);
      for (intptr_t Index = 0; (has <= 0) && (Index < List->nlibraries); ++Index)
      {
        ssh_gss_library * library = &List->libraries[Index];
        Ssh_gss_ctx ctx;
        ::ZeroMemory(&ctx, sizeof(ctx));
        has =
          ((library->acquire_cred(library, &ctx) == SSH_GSS_OK) &&
           (library->release_cred(library, &ctx) == SSH_GSS_OK)) ? 1 : 0;
      }
    }

    if (has < 0)
    {
      has = 0;
    }
  }
Exemple #14
0
//---------------------------------------------------------------------------
bool __fastcall HasGSSAPI(UnicodeString CustomPath)
{
  static int has = -1;
  if (has < 0)
  {
    Conf * conf = conf_new();
    ssh_gss_liblist * List = NULL;
    try
    {
      Filename * filename = filename_from_str(UTF8String(CustomPath).c_str());
      conf_set_filename(conf, CONF_ssh_gss_custom, filename);
      filename_free(filename);
      List = ssh_gss_setup(conf);
      for (int Index = 0; (has <= 0) && (Index < List->nlibraries); Index++)
      {
        ssh_gss_library * library = &List->libraries[Index];
        Ssh_gss_ctx ctx;
        memset(&ctx, 0, sizeof(ctx));
        has =
          ((library->acquire_cred(library, &ctx) == SSH_GSS_OK) &&
           (library->release_cred(library, &ctx) == SSH_GSS_OK)) ? 1 : 0;
      }
    }
    __finally
    {
      ssh_gss_cleanup(List);
      conf_free(conf);
    }

    if (has < 0)
    {
      has = 0;
    }
  }
Exemple #15
0
UTF8String Filename::getFilename() const
{
	UTF8String::const_reverse_iterator it = std::find_if(this->rbegin(), this->rend(), isPathSeparator);
	if (it==this->rend())
		return *this;
	return UTF8String(it.base(), this->end());
}
Exemple #16
0
/*#
    @method get_stock_id GtkToolButton
    @brief Returns the name of the stock item.
    @return the name of the stock item for button.
 */
FALCON_FUNC ToolButton::get_stock_id( VMARG )
{
    NO_ARGS
    MYSELF;
    GET_OBJ( self );
    const gchar* stock = gtk_tool_button_get_stock_id( (GtkToolButton*)_obj );
    vm->retval( UTF8String( stock ) );
}
Exemple #17
0
/*#
    @method to_string GtkTreePath
    @brief Generates a string representation of the path.
    @return a string

    This string is a ':' separated list of numbers.
    For example, "4:10:0:3" would be an acceptable return value for this string.
 */
FALCON_FUNC TreePath::to_string( VMARG )
{
    NO_ARGS
    MYSELF;
    gchar* s = gtk_tree_path_to_string( self->getTreePath() );
    vm->retval( UTF8String( s ) );
    g_free( s );
}
Exemple #18
0
cz::UTF8String Filename::removeBackslash() const
{
	UTF8String::const_reverse_iterator it2 = std::find_if(this->rbegin(), this->rend(), isPathSeparator);
	UTF8String::const_reverse_iterator it = std::find_if(this->rbegin(), this->rend(), notPathSeparator);
	if (it==this->rend())
		return *this;
	return UTF8String(this->begin(), it.base());
}
Exemple #19
0
//---------------------------------------------------------------------------
TKeyType KeyType(UnicodeString FileName)
{
  assert(ktUnopenable == SSH_KEYTYPE_UNOPENABLE);
  assert(ktSSHCom == SSH_KEYTYPE_SSHCOM);
  UTF8String UtfFileName = UTF8String(FileName);
  Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  TKeyType Result = (TKeyType)key_type(KeyFile);
  filename_free(KeyFile);
  return Result;
}
TKeyType KeyType(const UnicodeString & AFileName)
{
  assert(ktUnopenable == SSH_KEYTYPE_UNOPENABLE);
  assert(ktSSHCom == SSH_KEYTYPE_SSHCOM);
  UTF8String UtfFileName = UTF8String(AFileName);
  Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  TKeyType Result = static_cast<TKeyType>(key_type(KeyFile));
  filename_free(KeyFile);
  return Result;
}
Exemple #21
0
/**
 * Write the FString to a file.
 * Supports all combination of ANSI/Unicode files and platforms.
 */
bool FFileHelper::SaveStringToFile( const FString& String, const TCHAR* Filename,  EEncodingOptions::Type EncodingOptions, IFileManager* FileManager /*= &IFileManager::Get()*/ )
{
	// max size of the string is a UCS2CHAR for each character and some UNICODE magic 
	auto Ar = TUniquePtr<FArchive>( FileManager->CreateFileWriter( Filename, 0 ) );
	if( !Ar )
		return false;

	if( String.IsEmpty() )
		return true;

	const TCHAR* StrPtr = *String;

	bool SaveAsUnicode = EncodingOptions == EEncodingOptions::ForceUnicode || ( EncodingOptions == EEncodingOptions::AutoDetect && !FCString::IsPureAnsi(StrPtr) );
	if( EncodingOptions == EEncodingOptions::ForceUTF8 )
	{
		UTF8CHAR UTF8BOM[] = { 0xEF, 0xBB, 0xBF };
		Ar->Serialize( &UTF8BOM, ARRAY_COUNT(UTF8BOM) * sizeof(UTF8CHAR) );

		FTCHARToUTF8 UTF8String(StrPtr);
		Ar->Serialize( (UTF8CHAR*)UTF8String.Get(), UTF8String.Length() * sizeof(UTF8CHAR) );
	}
	else if ( EncodingOptions == EEncodingOptions::ForceUTF8WithoutBOM )
	{
		FTCHARToUTF8 UTF8String(StrPtr);
		Ar->Serialize((UTF8CHAR*)UTF8String.Get(), UTF8String.Length() * sizeof(UTF8CHAR));
	}
	else if (SaveAsUnicode)
	{
		UCS2CHAR BOM = UNICODE_BOM;
		Ar->Serialize( &BOM, sizeof(UCS2CHAR) );

		auto Src = StringCast<UCS2CHAR>(StrPtr, String.Len());
		Ar->Serialize( (UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR) );
	}
	else
	{
		auto Src = StringCast<ANSICHAR>(StrPtr, String.Len());
		Ar->Serialize( (ANSICHAR*)Src.Get(), Src.Length() * sizeof(ANSICHAR) );
	}

	return true;
}
Exemple #22
0
/*#
    @method get_accel_path GtkMenuItem
    @brief Retrieve the accelerator path that was previously set on menu_item.
    @return the accelerator path corresponding to this menu item's functionality, or NULL if not set
 */
FALCON_FUNC MenuItem::get_accel_path( VMARG )
{
    NO_ARGS
    MYSELF;
    GET_OBJ( self );
    const gchar* path = gtk_menu_item_get_accel_path( (GtkMenuItem*)_obj );
    if ( path )
        vm->retval( UTF8String( path ) );
    else
        vm->retnil();
}
Exemple #23
0
/*#
    @method get_label GtkToolButton
    @brief Returns the label used by the tool button, or NULL if the tool button doesn't have a label or uses a the label from a stock item.
    @return The label, or NULL
 */
FALCON_FUNC ToolButton::get_label( VMARG )
{
    NO_ARGS
    MYSELF;
    GET_OBJ( self );
    const gchar* lbl = gtk_tool_button_get_label( (GtkToolButton*)_obj );
    if ( lbl )
        vm->retval( UTF8String( lbl ) );
    else
        vm->retnil();
}
Exemple #24
0
/*#
    @method get_icon_name GtkToolButton
    @brief Returns the name of the themed icon for the tool button.
    @return the icon name or NULL if the tool button has no themed icon
 */
FALCON_FUNC ToolButton::get_icon_name( VMARG )
{
    NO_ARGS
    MYSELF;
    GET_OBJ( self );
    const gchar* ico = gtk_tool_button_get_icon_name( (GtkToolButton*)_obj );
    if ( ico )
        vm->retval( UTF8String( ico ) );
    else
        vm->retnil();
}
Exemple #25
0
TKeyType GetKeyType(const UnicodeString & AFileName)
{
  DebugAssert(ktUnopenable == SSH_KEYTYPE_UNOPENABLE);
#ifndef __linux__
  DebugAssert(ktSSH2PublicOpenSSH == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH);
#endif
  UTF8String UtfFileName = UTF8String(::ExpandEnvironmentVariables(AFileName));
  Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  TKeyType Result = static_cast<TKeyType>(key_type(KeyFile));
  filename_free(KeyFile);
  return Result;
}
Exemple #26
0
//---------------------------------------------------------------------------
UnicodeString __fastcall ReadResource(const UnicodeString ResName)
{
  void * Content;
  unsigned long Size;
  UnicodeString Result;

  if (GetResource(ResName, Content, Size))
  {
    Result = UnicodeString(UTF8String(static_cast<char*>(Content), Size));
  }

  return Result;
}
const wchar_t* HWTStr::get_wchar()
{
	const wchar_t* result = nil;
	
	if (fUTF8 != nil)
	{
		if (fBuffer.length() == 0)
			fBuffer = Convert(UTF8String(fUTF8, fLength));
		result = fBuffer.c_str();
	}

	return result;
}
Exemple #28
0
//
// _getPlatform1Encoding0String -- Private method
//
UTF8String FontFace::_getPlatform1Encoding0String( unsigned length, const FT_Byte *string) const{
	
	std::basic_string<UTF32> utf32;
	
	for(unsigned i=0;i<length;i++){
		
		utf32.push_back( Encoding::macRomanToUTF32(string[i]) );
		
	}
	
	// convert to utf-8:
	return UTF8String(utf32);
	
}
Exemple #29
0
//---------------------------------------------------------------------------
void TSessionLog::DoAddToSelf(TLogLineType AType, const UnicodeString & ALine)
{
  if (FTopIndex < 0)
  {
    FTopIndex = 0;
  }

  TStringList::AddObject(ALine, static_cast<TObject *>(reinterpret_cast<void *>(static_cast<size_t>(AType))));

  FLoggedLines++;

  if (LogToFile())
  {
    if (FFile == nullptr)
    {
      OpenLogFile();
    }

    if (FFile != nullptr)
    {
#if defined(__BORLANDC__)
      UnicodeString Timestamp = FormatDateTime(L" yyyy-mm-dd hh:nn:ss.zzz ", Now());
      UTF8String UtfLine = UTF8String(UnicodeString(LogLineMarks[Type]) + Timestamp + Line + "\n");
      fwrite(UtfLine.c_str(), UtfLine.Length(), 1, (FILE *)FFile);
#else
      unsigned short Y, M, D, H, N, S, MS;
      TDateTime DateTime = Now();
      DateTime.DecodeDate(Y, M, D);
      DateTime.DecodeTime(H, N, S, MS);
      UnicodeString dt = FORMAT(L" %04d-%02d-%02d %02d:%02d:%02d.%03d ", Y, M, D, H, N, S, MS);
      UnicodeString Timestamp = dt;
      UTF8String UtfLine = UTF8String(UnicodeString(LogLineMarks[AType]) + Timestamp + ALine + "\n");
      fprintf_s(static_cast<FILE *>(FFile), "%s", const_cast<char *>(AnsiString(UtfLine).c_str()));
#endif
    }
  }
}
Exemple #30
0
//
// _getPlatform3Encoding1String -- Private method
//
UTF8String FontFace::_getPlatform3Encoding1String( unsigned length, const FT_Byte *string) const{
	
	std::basic_string<UTF16> utf16;
	
	for(unsigned i=0;i<length;i+=2){
		
		UTF16 ch=0;
		ch=string[i];
		ch <<= 8;
		ch |= string[i+1];
		utf16.push_back( ch );
		
	}
	
	// convert to utf-8:
	return UTF8String(utf16);
	
}