Пример #1
0
 inline Unicode
 decode(const Bytes& object) const
 {
   unicode code = 0;
   size_t offset = 0;
   unicode* decptr = NULL;
   size_t len = object.length();
   const bytechar* encptr = object;
   decptr = new unicode[len];
   for (size_t i = 0; i < len; ++i)
   {
     code = this->bytetouc(encptr[i]);
     if (code == 0x110000)
     {
       delete[] decptr;
       throw DecodeError(UNICODE_STATE_ILLEGAL, offset, *this);
     }
     decptr[i] = static_cast<unicode>(code);
     ++offset;
   }
   return Unicode(decptr, len);
 }
std::string executable_path() {
  wchar_t buf[10000];
  DWORD bufsize = sizeof(buf);
  GetModuleFileNameW(NULL, buf, bufsize);
  return Unicode(buf).utf8();
}
Пример #3
0
void ZhscWidget::educe()
{
  if ( !bConStatus ) 
  {
    return;
  }

  uint len = 0;
  uint index = 0;
  int n = 0;

  QString tmp;

  QChar c( 0x2028 );

  tePoem->setTextFormat( Qt::PlainText );
  teMemo->setTextFormat( Qt::PlainText );
  tePoet->setTextFormat( Qt::PlainText );

  tmp = tePoem->text() + "\n" + teMemo->text() + "\n" + tePoet->text();

  tePoem->setTextFormat( Qt::AutoText );
  teMemo->setTextFormat( Qt::AutoText );
  tePoet->setTextFormat( Qt::AutoText );

  len = tmp.length();
  
  while ( 1 )
  {
    n = tmp.find( c, index );
    if ( n < 0 )
      break;
    tmp.replace( n, 1, "\n" );
    index = n;
  }

  QString sFileName;

  QFileDialog *fd = new QFileDialog( this );

  fd->setMode( QFileDialog::AnyFile );
  fd->setFilter( Unicode( "所有文件 (*.*)" ) );
  fd->setViewMode( QFileDialog::Detail );
  fd->setCaption( Unicode( "中华诗词 Qt版" ) );

  if ( fd->exec() == QDialog::Accepted )
  {
    sFileName = fd->selectedFile(); 
    if ( QFile::exists( sFileName ) )
    {
      if ( QMessageBox::warning( NULL, Unicode( "中华诗词 Qt版" ),
          Unicode( "这个文件已经存在,覆盖它?" ),
          Unicode( "确定" ),
          Unicode( "取消" ), 0, 0, 1 ) == 1)
      {
        delete fd;
        return;
      }
    }
    delete fd;
  }

  if ( sFileName != "" )
  {
    QFile f( sFileName );
    if ( f.open( IO_WriteOnly | IO_Truncate ) ) 
    {
      QTextCodec *codec = new QGb18030Codec();
      QTextStream ts( &f );
      ts.setCodec( codec );
      ts << tmp;
      f.close();
    }
  }
  
  return;
}