本文整理汇总了C++中qstringlist::iterator::truncate方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::truncate方法的具体用法?C++ iterator::truncate怎么用?C++ iterator::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qstringlist::iterator
的用法示例。
在下文中一共展示了iterator::truncate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destDir
Calamares::JobResult
CreateUserJob::exec()
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QDir destDir( gs->value( "rootMountPoint" ).toString() );
if ( gs->contains( "sudoersGroup" ) &&
!gs->value( "sudoersGroup" ).toString().isEmpty() )
{
QFileInfo sudoersFi( destDir.absoluteFilePath( "etc/sudoers.d/10-installer" ) );
if ( !sudoersFi.absoluteDir().exists() )
return Calamares::JobResult::error( tr( "Sudoers dir is not writable." ) );
QFile sudoersFile( sudoersFi.absoluteFilePath() );
if (!sudoersFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
return Calamares::JobResult::error( tr( "Cannot create sudoers file for writing." ) );
QString sudoersGroup = gs->value( "sudoersGroup" ).toString();
QTextStream sudoersOut( &sudoersFile );
sudoersOut << QString( "%%1 ALL=(ALL) ALL\n" ).arg( sudoersGroup );
if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) )
return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) );
}
QFileInfo groupsFi( destDir.absoluteFilePath( "etc/group" ) );
QFile groupsFile( groupsFi.absoluteFilePath() );
if ( !groupsFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
return Calamares::JobResult::error( tr( "Cannot open groups file for reading." ) );
QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() );
QStringList groupsLines = groupsData.split( '\n' );
for ( QStringList::iterator it = groupsLines.begin();
it != groupsLines.end(); ++it )
{
int indexOfFirstToDrop = it->indexOf( ':' );
it->truncate( indexOfFirstToDrop );
}
foreach ( const QString& group, m_defaultGroups )
if ( !groupsLines.contains( group ) )
CalamaresUtils::System::instance()->
targetEnvCall( { "groupadd", group } );
QString defaultGroups = m_defaultGroups.join( ',' );
if ( m_autologin )
{
QString autologinGroup;
if ( gs->contains( "autologinGroup" ) &&
!gs->value( "autologinGroup" ).toString().isEmpty() )
autologinGroup = gs->value( "autologinGroup" ).toString();
else
autologinGroup = QStringLiteral( "autologin" );
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", autologinGroup } );
defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) );
}
int ec = CalamaresUtils::System::instance()->
targetEnvCall( { "useradd",
"-m",
"-s",
"/bin/bash",
"-U",
"-G",
defaultGroups,
m_userName } );
if ( ec )
return Calamares::JobResult::error( tr( "Cannot create user %1." )
.arg( m_userName ),
tr( "useradd terminated with error code %1." )
.arg( ec ) );
ec = CalamaresUtils::System::instance()->targetEnvCall( { "chfn", "-f", m_fullName, m_userName } );
if ( ec )
return Calamares::JobResult::error( tr( "Cannot set full name for user %1." )
.arg( m_userName ),
tr( "chfn terminated with error code %1." )
.arg( ec ) );
ec = CalamaresUtils::System::instance()->
targetEnvCall( { "chown",
"-R",
QString( "%1:%2" ).arg( m_userName )
.arg( m_userName ),
QString( "/home/%1" ).arg( m_userName ) } );
if ( ec )
return Calamares::JobResult::error( tr( "Cannot set home directory ownership for user %1." )
.arg( m_userName ),
tr( "chown terminated with error code %1." )
.arg( ec ) );
return Calamares::JobResult::ok();
}
示例2: save
//.........这里部分代码省略.........
if ( text.startsWith( '\n' ) )
list.prepend( QString() );
if(list.isEmpty())
list.append( QString() );
if( list.count() > 1 )
list.prepend( QString() );
stream << keyword << ' ';
QStringList::const_iterator it;
for( it = list.constBegin(); it != list.constEnd(); ++it )
stream << '\"' << (*it) << "\"\n";
return;
}
#endif
if ( m_wrapWidth == 0 ) // Unknown special wrapping, so assume "no wrap" instead
{
// No wrapping (like Gettext's --no.wrap or -w0 )
// we need to remove the \n characters, as they are extra characters
QString realText( text );
realText.remove( '\n' );
stream << keyword << " \"" << realText << "\"\n";
return;
}
else if ( m_wrapWidth < 0 )
{
// No change in wrapping
QStringList list = text.split( '\n');
if (list.count()>1 || startedWithEmptyLine /* || keyword.length()+3+text.length()>=80*/)
list.prepend(QString());
stream << keyword << " ";
QStringList::const_iterator it;
for( it = list.constBegin(); it != list.constEnd(); ++it )
stream << "\"" << (*it) << "\"\n";
return;
}
// lazy wrapping
QStringList list = text.split( '\n', QString::SkipEmptyParts );
if ( text.startsWith( '\n' ) )
list.prepend( QString() );
if(list.isEmpty())
list.append( QString() );
static QRegExp breakStopReForHtml("[ >.%]", Qt::CaseSensitive, QRegExp::Wildcard);
QRegExp breakStopRe=containsHtml?breakStopReForHtml:QRegExp("[ .%]", Qt::CaseSensitive, QRegExp::Wildcard);
int max=m_wrapWidth-2;
bool prependedEmptyLine=false;
QStringList::iterator itm;
for( itm = list.begin(); itm != list.end(); ++itm )
{
if (list.count()==1 && keyword.length()+1+itm->length()>=max)
{
prependedEmptyLine=true;
itm=list.insert(itm,QString());
}
if (itm->length()>max)
{
int pos = itm->lastIndexOf(breakStopRe,max-1);
if (pos>0)
{
int pos2 = itm->indexOf('<',pos);
if (pos2>0&&pos2<max-1)
pos=itm->indexOf('<',pos);
++pos;
}
else
pos=max;
//itm=list.insert(itm,itm->left(pos));
QString t=*itm;
itm=list.insert(itm,t);
itm++;
if (itm != list.end())
{
(*itm)=itm->remove(0,pos);
itm--;
if (itm != list.end())
itm->truncate(pos);
}
}
}
if( !prependedEmptyLine && list.count() > 1 )
list.prepend( QString() );
stream << keyword << " ";
QStringList::const_iterator it;
for( it = list.constBegin(); it != list.constEnd(); ++it )
stream << "\"" << (*it) << "\"\n";
}