// Compares 2 strings optionally ignoring punctuation
int TesseractCubeCombiner::CompareStrings(const string &str1,
                                          const string &str2,
                                          bool ignore_punc,
                                          bool ignore_case) {
  if (!ignore_punc && !ignore_case) {
    return str1.compare(str2);
  }
  string norm_str1 = NormalizeString(str1, ignore_punc, ignore_case);
  string norm_str2 = NormalizeString(str2, ignore_punc, ignore_case);
  return norm_str1.compare(norm_str2);
}
void MainWindow::on_pushButton_2_clicked()
{
    QString ctext = ui->cipherText2->toPlainText();
    QString key = ui->keyText->text();
    QString ptext = "";
    QChar kernel[5][5];

    ctext = ctext.replace('j','i');

    NormalizeString(&ctext);
    NormalizeString(&key);
    BuildKernel(key, kernel);
    int ctextLen = ctext.length();

    for(int i=0; i<ctextLen; i++)
    {
        QChar token1 = ctext[i];
        i++;
        QChar token2;
        if(i < ctextLen)
            token2 = ctext[i];
        else
            token2 = 'q';

        int x1,y1,x2,y2;
        FindInKernel(kernel, token1,&x1,&y1);
        FindInKernel(kernel, token2,&x2,&y2);
        if(x1 == x2)
        {
            y1 = (y1+4) % 5;
            y2 = (y2+4) % 5;
            ptext += kernel[y1][x1];
            ptext += kernel[y2][x2];
        }
        else if(y1 == y2)
        {
            x1 = (x1+4) % 5;
            x2 = (x2+4) % 5;
            ptext += kernel[y1][x1];
            ptext += kernel[y2][x2];
        }
        else
        {
            ptext += kernel[y1][x2];
            ptext += kernel[y2][x1];
        }
    }

    //RemoveXForDuplicates(&ptext);
    ui->plainText2->setPlainText(ptext);
}
Example #3
0
int ZipPlatform::MultiByteToWide(const char* szIn, int iInSize, CZipString& szOut, UINT uCodePage)
{	
	szOut.Empty();
	if (iInSize < 0)
	{
		iInSize = (int)std::string(szIn).length();
	}	
	if (iInSize == 0)
	{		
		return 0;
	}
	
	// iLen doesn't include terminating character
	DWORD dwFlags = uCodePage <= CP_OEMCP ? MB_PRECOMPOSED : 0;
	int iLen = MultiByteToWideChar(uCodePage, dwFlags, szIn, iInSize, NULL, 0);
	if (iLen > 0)
	{
		iLen = MultiByteToWideChar(uCodePage, dwFlags, szIn, iInSize, szOut.GetBuffer(iLen), iLen);
		szOut.ReleaseBuffer(iLen);
		ASSERT(iLen > 0);
		if (iLen == 0)
			return -1;
#ifdef _ZIP_UNICODE_NORMALIZE
		// if there is a problem with compilation here, you may need uncomment the block defining WINVER = 0x0600 at the bottom of _features.h file
		if (IsNormalizedString(NormalizationC, szOut, iLen + 1) == TRUE)
			return iLen;		
		int iNewLen = NormalizeString(NormalizationC, szOut, iLen, NULL, 0);
		if (iNewLen <= 0)
		{
			return iLen;
		}
		CZipString szNormalized;
		iNewLen = NormalizeString(NormalizationC, szOut, iLen, szNormalized.GetBuffer(iNewLen), iNewLen);		
		if (iNewLen <= 0)
		{
			szNormalized.ReleaseBuffer(0);
			return iLen;
		}
		szNormalized.ReleaseBuffer(iNewLen);
		szOut = szNormalized;
		return iNewLen;
#else
		return iLen;
#endif
	}
	else
	{		
		return -1;
	}	
}
void MainWindow::on_pushButton_clicked()
{    
    QString ptext = ui->plainText->toPlainText();
    QString key = ui->keyText->text();
    QString ctext = "";
    QChar kernel[5][5];

    NormalizeString(&ptext);    
    FixDuplicateChar(&ptext);
    NormalizeString(&key);
    BuildKernel(key, kernel);    


    int ptextLen = ptext.length();

    for(int i=0; i<ptextLen; i++)
    {
        QChar token1 = ptext[i];
        i++;
        QChar token2;
        if(i < ptextLen)
            token2 = ptext[i];
        else
            token2 = 'q';

        int x1,y1,x2,y2;
        FindInKernel(kernel, token1,&x1,&y1);
        FindInKernel(kernel, token2,&x2,&y2);
        if(x1 == x2)
        {
            y1 = (y1+1) % 5;
            y2 = (y2+1) % 5;
            ctext += kernel[y1][x1];
            ctext += kernel[y2][x2];
        }
        else if(y1 == y2)
        {
            x1 = (x1+1) % 5;
            x2 = (x2+1) % 5;
            ctext += kernel[y1][x1];
            ctext += kernel[y2][x2];
        }
        else
        {
            ctext += kernel[y1][x2];
            ctext += kernel[y2][x1];
        }
    }
    ui->cipherText->setPlainText(ctext);
}
Example #5
0
string DaemonConfigProjectApplication::Capabilities( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "capabilities_file" ) );

 if( Data.empty() )
 {
  VERBOSE_DEBUG_LOG( "DaemonConfigProjectApplication::Capabilities; No data in capabilities_file tag found" );

  Data = NormalizeString( Parse_XML( ApplicationCache, "capabilities" ) );

  if( Data.empty() )
   VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Capabilities; No data in capabilities tag found" )
  else
   VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Capabilities; Returned " << Data );
 }
Example #6
0
void CTextBaseLine::WriteOutput(CFX_WideString& str, FX_FLOAT leftx, FX_FLOAT pagewidth,
                                int iTextWidth)
{
    int lastpos = -1;
    for (int i = 0; i < m_TextList.GetSize(); i ++) {
        CTextBox* pText = (CTextBox*)m_TextList.GetAt(i);
        int xpos;
        if (pText->m_pColumn) {
            xpos = (int)((pText->m_pColumn->m_AvgPos - leftx) * iTextWidth / pagewidth + 0.5);
            xpos -= pText->m_Text.GetLength();
        } else {
            xpos = (int)((pText->m_Left - leftx) * iTextWidth / pagewidth + 0.5);
        }
        if (xpos <= lastpos) {
            xpos = lastpos + 1;
        }
        for (int j = lastpos + 1; j < xpos; j ++) {
            str += ' ';
        }
        CFX_WideString sSrc(pText->m_Text);
        NormalizeString(sSrc);
        str += sSrc;
        str += ' ';
        lastpos = xpos + pText->m_Text.GetLength();
    }
}
Example #7
0
void NumValidatorBase::OnPaste(wxClipboardTextEvent& event)
{
   event.Skip(false);

   wxTextEntry * const control = GetTextEntry();
   if ( !control )
   {
      return;
   }

   wxClipboardLocker cb;
//    if (!wxClipboard::Get()->IsSupported(wxDataFormat(wxDF_TEXT)))
   if (!wxClipboard::Get()->IsSupported(wxDF_TEXT))
   {
      return;
   }

   wxTextDataObject data;
   if (!wxClipboard::Get()->GetData( data ))
   {
      return;
   }

   wxString toPaste = data.GetText();
   wxString val;
   int pos;
   GetCurrentValueAndInsertionPoint(val, pos);

   for (size_t i = 0, cnt = toPaste.Length(); i < cnt; i++)
   {
      const wxChar ch = toPaste[i];

      // Check if this character is allowed in the current state.
      if ( IsCharOk(val, pos, ch) )
      {
         val = GetValueAfterInsertingChar(val, pos++, ch);
      }
      else if ( !wxValidator::IsSilent() )
      {
               wxBell();
      }
   }

   // When we change the control value below, its "modified" status is reset
   // so we need to explicitly keep it marked as modified if it was so in the
   // first place.
   //
   // Notice that only wxTextCtrl (and not wxTextEntry) has
   // IsModified()/MarkDirty() methods hence the need for dynamic cast.
   wxTextCtrl * const text = wxDynamicCast(m_validatorWindow, wxTextCtrl);
   const bool wasModified = text ? text->IsModified() : false;

   // Use SetValue because effect still needs EVT_TEXT (bug 1357)
   control->SetValue(NormalizeString(val));

   if ( wasModified )
   {
      text->MarkDirty();
   }
}
Example #8
0
string DaemonConfigProject::Owner_Allow( void )
{
 string Data = NormalizeString( Parse_XML( ProjectCache, "owner_allow" ) );
 if( Data.empty() )
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProject::Owner_Allow; No data in owner_allow tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProject::Owner_Allow; Returned " << Data );
}
Example #9
0
int DaemonConfigProjectApplication::Job_Limit( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "job_limit" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfigProjectApplication::Job_Limit; No data in job_limit tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfigProjectApplication::Job_Limit; Returned " << Data );
}
Example #10
0
string DaemonConfigProjectApplication::Application_Name( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "application_name" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( Data, "DaemonConfigProjectApplication::Application_Name; No data in application_name tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Application_Name; Returned " << Data );
}
Example #11
0
int DaemonConfigProjectApplication::Job_Sandbox_UID( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "job_sandbox_uid" ) );
 if( Data.empty() )
  VERBOSE_DEBUG_LOG_RETURN( 0, "DaemonConfigProjectApplication::Job_Sandbox_UID; No valid job_sandbox_uid tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfigProjectApplication::Job_Sandbox_UID; Returned " << Data );
}
Example #12
0
int DaemonConfigProject::Number_Of_Applications( void )
{
 string Data = NormalizeString( Parse_XML( ProjectCache, "number_of_applications" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfigProject::Number_Of_Applications; No data in number_of_applications tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfigProject::Number_Of_Applications; Returned " << Data );
}
Example #13
0
string DaemonConfigProject::Project_Name( void )
{
 string Data = NormalizeString( Parse_XML( ProjectCache, "project_name" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( Data, "DaemonConfigProject::Project_Name; No data in project_name tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProject::Project_Name; Returned " << Data );
}
Example #14
0
string DaemonConfigProject::Project_Master_Server( void )
{
 string Data = NormalizeString( Parse_XML( ProjectCache, "project_master_server" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( Data, "DaemonConfigProject::Project_Master_Server; No data in project_master_server tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProject::Project_Master_Server; Returned " << Data );
}
Example #15
0
int DaemonConfigProjectApplication::Max_Output_Size( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "max_output_size" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfigProjectApplication::Max_OutputSize; No data in max_output_size tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfigProjectApplication::Max_Output_Size; Returned " << Data );
}
Example #16
0
int DaemonConfig::Job_Limit( void )
{
 string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "job_limit" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfig::Job_Limit; No data in job_limit tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfig::Job_Limit; Returned " << Data );
}
Example #17
0
int DaemonConfig::Number_Of_Projects( void )
{
 string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "number_of_projects" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfig::Number_Of_Projects; No data in number_of_projects tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( atoi( Data.c_str() ), "DaemonConfig::Number_Of_Projects; Returned " << Data );
}
Example #18
0
string DaemonConfig::Owner_Deny( void )
{
 string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "owner_deny" ) );
 if( Data.empty() )
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::Owner_Deny; No data in owner_deny tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::Owner_Deny; Returned " << Data );
}
Example #19
0
string DaemonConfigProjectApplication::Owner_Deny( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "owner_deny" ) );
 if( Data.empty() )
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Owner_Deny; No data in owner_deny tag found" )
 else
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Owner_Deny; Returned " << Data );
}
Example #20
0
string DaemonConfig::RunDirectory( void )
{
 string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "run_directory" ) );
 if( Data.empty() )
  CRITICAL_LOG_RETURN( Data, "DaemonConfig::RunDirectory; No data in run_directory tag found" )
 else {
  Data = AbsolutePath( Data );
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::RunDirectory; Returned " << Data );
 }
}
Example #21
0
string DaemonConfigProjectApplication::Job_Abort_Script( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "job_abort_script" ) );
 if( Data.empty() ) {
  CRITICAL_LOG_RETURN( Data, "DaemonConfigProjectApplication::Job_Abort_Script; No data in job_abort_script tag found" )
 } else {
  Data = AbsolutePath( Data );
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Job_Abort_Script; Returned " << Data );
 }
}
Example #22
0
string DaemonConfig::Resource_Certificate_File( void )
{
 string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "resource_certificate_file" ) );
 if( Data.empty() ) {
  CRITICAL_LOG_RETURN( Data, "DaemonConfig::Resource_Certificate_File; No data in resource_certificate_file tag found" )
 } else {
  Data = AbsolutePath( Data );
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::Resource_Certificate_File; Returned " << Data );
 }
}
Example #23
0
string DaemonConfigProjectApplication::Check_System_Limits_Script( void )
{
 string Data = NormalizeString( Parse_XML( ApplicationCache, "check_system_limits_script" ) );
 if( Data.empty() ) {
  CRITICAL_LOG_RETURN( Data, "DaemonConfigProjectApplication::Check_System_Limits_Script; No data in check_system_limits_script tag found" )
 } else {
  Data = AbsolutePath( Data );
  VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Check_System_Limits_Script; Returned " << Data );
 }
}
Example #24
0
int DaemonConfig::ReloadConfigFromFile( string ConfigFile )
{
 NORMAL_LOG( "DaemonConfig::ReloadConfigFromFile; Reloading config from file " << ConfigFile );

 ConfigurationXML = NormalizeString( Parse_XML( ReadStringFromFile( ConfigFile ), "LGI" ) );

 if( ConfigurationXML.empty() )
  CRITICAL_LOG_RETURN( 0, "DaemonConfig::ReloadConfigFromFile; Reload of config file " << ConfigFile << " failed" )
 else
  DEBUG_LOG_RETURN( IsValidConfigured(), "DaemonConfig::ReloadConfigFromFile; The configuration reloaded: " << ConfigurationXML );
}
Example #25
0
DaemonConfig::DaemonConfig( string ConfigFile )
{
 NORMAL_LOG( "DaemonConfig::DaemonConfig; Reading config file " << ConfigFile );

 ConfigurationXML = ReadStringFromFile( ConfigFile );

 DEBUG_LOG( "DaemonConfig::DaemonConfig; The configuration read in: " << ConfigurationXML );

 ConfigurationXML = NormalizeString( Parse_XML( ConfigurationXML, "LGI" ) );

 if( ConfigurationXML.empty() )
  CRITICAL_LOG( "DaemonConfig::DaemonConfig; No data in LGI tag found" );
}
Example #26
0
static walk_result FindTheMad( mad_handle mh, void *d )
{
    struct find_mad     *fd = d;
    char                buff[80];
//    char                *p;

    MADNameFile( mh, buff, sizeof( buff ) );
//    p = SkipPathInfo( buff, 0 );
    SkipPathInfo( buff, 0 );
    if( memicmp( buff, fd->name, fd->len ) == 0 ) {
        fd->mad = mh;
        return( WR_STOP );
    }
    MADNameDescription( mh, buff, sizeof( buff ) );
    NormalizeString( buff );
    if( memicmp( buff, fd->name, fd->len ) == 0 ) {
        fd->mad = mh;
        return( WR_STOP );
    }
    return( WR_CONTINUE );
}
Example #27
0
void wxNumValidatorBase::OnKillFocus(wxFocusEvent& event)
{
    wxTextEntry * const control = GetTextEntry();
    if ( !control )
        return;

    // When we change the control value below, its "modified" status is reset
    // so we need to explicitly keep it marked as modified if it was so in the
    // first place.
    //
    // Notice that only wxTextCtrl (and not wxTextEntry) has
    // IsModified()/MarkDirty() methods hence the need for dynamic cast.
    wxTextCtrl * const text = wxDynamicCast(m_validatorWindow, wxTextCtrl);
    const bool wasModified = text ? text->IsModified() : false;

    control->ChangeValue(NormalizeString(control->GetValue()));

    if ( wasModified )
        text->MarkDirty();

    event.Skip();
}
Example #28
0
bool ConfigFile::Load() {
    FILE *file = 0;
    if ((file = fopen(path.c_str(), "r")) == NULL) {
        perror("no config file found!");
        return false;
    }
    char buffer[1024];
    fread(buffer, sizeof(char), 1024, file);
    string content = string(buffer);

    NormalizeString(content);

    size_t pos1 = 0, pos2;
    string part;
    while ((pos2 = content.find(";", pos1)) != string::npos) {
        part = content.substr(pos1, pos2-pos1);
        ParseAndAddAttribute(part);
        pos1 = pos2 + 1;
    }
    fclose(file);
    return true;
}
Example #29
0
static
PyObject* downcast(PyObject* self, PyObject* args) {
    PyObject *obj, *cls;
    if (!PyArg_ParseTuple(args, "OO", &obj, &cls)) {
        return NULL;
    }

    if ((PyObject *) Py_TYPE(obj) == cls) {
        Py_INCREF(obj);
        return obj;
    }

    PyObject* apiModule = GetAPIModule();

    auto_pyobject fromTy = PyObject_GetAttrString(obj, "_llvm_type_");
    auto_pyobject toTy = PyObject_GetAttrString(cls, "_llvm_type_");

    std::ostringstream oss;

    auto_pyobject fromTyStr = PyObject_Str(*fromTy);
    auto_pyobject toTyStr = PyObject_Str(*toTy);

    const char * fromCS = PyString_AsString(*fromTyStr);
    const char * toCS = PyString_AsString(*toTyStr);

    oss << "downcast_";
    NormalizeString(oss, fromCS);
    oss << "_to_";
    NormalizeString(oss, toCS);
    std::string fname = oss.str();

    auto_pyobject caster = PyObject_GetAttrString(GetDowncastModule(),
                                                  fname.c_str());

    if (!caster) {
        std::ostringstream oss;
        oss << "Downcast from " << fromCS << " to " << toCS;
        std::string errmsg = oss.str();
        PyErr_SetString(PyExc_TypeError, errmsg.c_str());
        return NULL;
    }

    auto_pyobject oldObj = Unwrap(obj);
    auto_pyobject newObj = PyObject_CallFunctionObjArgs(*caster, *oldObj,
                                                        NULL);

    bool used_to_own = HasOwnership(*oldObj);

    PyObject *result = Wrap(*newObj, !used_to_own);

    int status = PyObject_Not(result);
    switch(status) {
    case 0:
        return result;
    case 1:
    default:
        PyErr_SetString(PyExc_ValueError, "Downcast failed");
        Py_XDECREF(result);
        return NULL;
    }
}
Example #30
0
// Check if normalized and display normalized output for a particular normalization form 
void TryNormalization(NORM_FORM form, LPWSTR strInput)
{
	// Test if the string is normalized 
	if (IsNormalizedString(form, strInput, -1))
	{
		wprintf(L"Already normalized in this form\n");
	}
	else
	{
		// It was not normalized, so normalize it 
		int    iSizeGuess;
		LPWSTR pBuffer;

		// How big is our buffer (quick guess, usually enough) 
		iSizeGuess = NormalizeString(form, strInput, -1, NULL, 0);

		if (iSizeGuess == 0)
		{
			wprintf(L"Error %d checking for size\n", GetLastError());
		}

		while (iSizeGuess > 0)
		{
			pBuffer = (LPWSTR)malloc(iSizeGuess * sizeof(WCHAR));
			if (pBuffer)
			{
				// Normalize the string 
				int iActualSize = NormalizeString(form, strInput, -1, pBuffer, iSizeGuess);
				iSizeGuess = 0;
				if (iActualSize <= 0 && GetLastError() != ERROR_SUCCESS)
				{
					// Error during normalization 
					wprintf(L"Error %d during normalization\n", GetLastError());
					if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
					{
						// If the buffer is too small, try again with a bigger buffer. 
						wprintf(L"Insufficient buffer, new suggested buffer size %d\n", -iActualSize);
						iSizeGuess = -iActualSize;
					}
					else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
					{
						wprintf(L"Invalid Unicode found at input character index %d\n", -iActualSize);
					}
				}
				else
				{
					// Display the normalized string 
					DumpString(pBuffer);
				}

				// Free the buffer 
				free(pBuffer);
			}
			else
			{
				wprintf(L"Error allocating buffer\n");
				iSizeGuess = 0;
			}
		}
	}
}