bool类型OK();end;

True, False And Nil Objects In Ruby
Share this:您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
《算法分析》-10回溯法详解.ppt 24页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
需要金币:350 &&
你可能关注的文档:
··········
··········
克服困难性克服困难性穷举法、归纳法、分治法、动态规划、贪心法、图的搜索等方法是有效的算法,但是,大量的实际问题尚无有效的算法,这些问题的时间测度常常需要用年或世纪。这些困难问题的解决有三套方案:1、基于搜索剪枝技术。2、基于精确的概率概念。3、基于近似的解。基于搜索剪枝技术此方法适用于那些在平均情况下能够显示出良好的时间复杂性,但在最坏情况下很难得到多项式解法的问题。此方法对问题的状态空间进行搜索,并在搜索过程中进行剪枝。两个搜索剪枝技术:回溯法分支限界法基于精确的概率概念一个简单的决策或测试过程,能够精确的完成一个任务,经过这样的反复测试,将能够构造解,或者增加解的可信度到所期望的程度。方法:随机算法基于近似的解适用于得到渐进的解,利用此方法,可以通过在解的质量上的妥协以换得更快的(多项式时间)解。方法:近似算法回溯法学习要点理解回溯法的深度优先搜索策略。思路:状态空间---穷举设计求解过程---深度优先搜索+剪枝通过应用范例学习回溯法的设计策略。(1)图的3着色问题(2)8皇后问题;3着色问题:3着色问题:求解过程---深度优先搜索+剪枝输入:无向图G=(V,E)输出:G的顶点的3着色,其中每个c[j]为1,2,31.fork=1ton2.c[k]=03.endfor4.flag=flase5.k=16.whilek&=17.whilec[k]&=28.c[k]=c[k]+19.ifc为合法着色thensetflag=true且退出10.elseifc是部分解thenk=k+1{前进}11.endwhile12.c[k]=013.k=k-1{回溯,就是剪枝}14.endwhile15.ifflagthenoutputc16.elseoutput“nosolution”8皇后问题如何在8*8的国际象棋棋盘上安排8个皇后,使得没有两个皇后能互相攻击?约束条件:如果两个皇后在同一行、同一列、同一条对角线上,她们能互相攻击。可以推导到N皇后问题。在n×n格的棋盘上放置彼此不受攻击的n个皇后。按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。n后问题等价于在n×n格的棋盘上放置n个皇后,任何2个皇后不放在同一行或同一列或同一斜线上。4皇后举例4皇后举例:P316,图12.2问题的解空间递归回溯 输入:集合X1,X2,…,Xn的清楚的或隐含的描述输出:解向量v=(x1,x2,…,xi),0&=i&=n1.v={}2.flag=false3.advance(1)4.ifflagthenoutputv5.elseoutput“nosolution”advance(k)1.forx?Xk2.xk=x;将xk加入v3.ifv为最终解thensetflag=trueandexit4.elseifv是部分解thenadvance(k+1)5.endfor输入:集合X1,X2,…Xn的清楚的或隐含的描述输出:解向量v=(x1,x2,…,xi),0&=i&=n1.v={}2.flag=flase3.k=14.whilek&=15.whileXk没有被穷举6.xk中的下一个元素;将xk加入v7.ifv为合法着色thensetflag=true且退出8.elseifv是部分解thenk=k+1{前进}9.endwhile10.重置Xk,使得下一个元素排在第一位11.k=k-1{回溯,就是剪枝}12.endwhile13.ifflagthenoutputv14.elseoutput“nosolution”**图的m着色问题给定无向连通图G和m种不同的颜色。用这些颜色为图G的各顶点着色,每个顶点着一种颜色。是否有一种着色法使G中每条边的2个顶点着不同颜色。这个问题是图的m可着色判定问题。若一个图最少需要m种颜色才能使图中每条边连接的2个顶点着不同颜色,则称这个数m为该图的色数。求一个图的色数m的问题称为图的m可着色优化问题。状态空间---穷举设计n个顶点的图有3n个可能的着色方案,建立搜索树。n=3时的搜索树解向量:(x1,x2,…,xn)表示顶点i所着颜色x[i],a[k][j]为图矩阵。可行性约束函数:顶点i与已着色的相邻顶点颜色不重复。图的m着色问题voidColor(intt){if(t&n){for(inti=1;i&=n;i++)cout&&x[i]&&'';cout&&}elsefor(inti=1;i&=m;i++){x[t]=i;if(Ok(t))Color(t+1);}}boolOk(intk){//检查颜色可用性for(intj=1;j&=n;j++)if((a[k][j]==1)&&(
正在加载中,请稍后...QStringRef
QStringRef Class
class provides a thin wrapper around
substrings.
Header: #include &QStringRef&
qmake: QT += core Since:
Note: All functions in this class are .
Public Types
Public Functions
(const QString *string, int position, int length)
(const QString *string)
(const QStringRef &other)
(QStringRef &&other)
QStringRef (QString *string) const
const QChar (int position) const
const_iterator () const
const_iterator () const
const_iterator () const
int (const QStringRef &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const QChar *() const
bool (const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int () const
int (const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const_reverse_iterator () const
const_reverse_iterator () const
const QChar *() const
const_iterator () const
bool (const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (const QString &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QChar ch, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QLatin1String str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (const QStringRef &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool () const
bool () const
int (const QString &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QChar ch, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (QLatin1String str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int (const QStringRef &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QStringRef (int n) const
int () const
int (const QStringRef &other) const
int (const QString &other) const
QStringRef (int position, int n = -1) const
int () const
const_reverse_iterator () const
const_reverse_iterator () const
QStringRef (int n) const
int () const
QVector&QStringRef& (const QString &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QVector&QStringRef& (QChar sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool (const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const QString *() const
double (bool *ok = Q_NULLPTR) const
float (bool *ok = Q_NULLPTR) const
int (bool *ok = Q_NULLPTR, int base = 10) const
QByteArray () const
QByteArray () const
long (bool *ok = Q_NULLPTR, int base = 10) const
qlonglong (bool *ok = Q_NULLPTR, int base = 10) const
short (bool *ok = Q_NULLPTR, int base = 10) const
QString () const
uint (bool *ok = Q_NULLPTR, int base = 10) const
ulong (bool *ok = Q_NULLPTR, int base = 10) const
qulonglong (bool *ok = Q_NULLPTR, int base = 10) const
ushort (bool *ok = Q_NULLPTR, int base = 10) const
QVector&uint& () const
QByteArray () const
QStringRef () const
void (int position)
const QChar *() const
bool (const char *s) const
bool (const char *s) const
bool (const char *s) const
QStringRef &(QStringRef &&other)
QStringRef &(const QStringRef &other)
QStringRef &(const QString *string)
bool (const char *s) const
bool (const char *s) const
bool (const char *s) const
QChar (int position) const
Static Public Members
int (const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
int (const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
int (const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
int (const QStringRef &s1, const QString &s2)
int (const QStringRef &s1, const QStringRef &s2)
Related Non-Members
bool (const QStringRef &s1, const QStringRef &s2)
bool (const QStringRef &s1, const QStringRef &s2)
bool (const QStringRef &s1, const QStringRef &s2)
bool (const QString &s1, const QStringRef &s2)
bool (QLatin1String s1, const QStringRef &s2)
bool (const QStringRef &s1, const QStringRef &s2)
bool (const QStringRef &s1, const QStringRef &s2)
Detailed Description
class provides a thin wrapper around
substrings.
provides a read-only subset of the
A string reference explicitly references a portion of a () with a given (), starting at a specific (). Calling () returns a copy of the data as a real
This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing
instances.
avoids the memory allocation and reference counting overhead of a standard
by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.
For most users, there are no semantic benefits to using
instead of
requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.
Warning: A
is only valid as long as the referenced string exists. If the original string is deleted, the string reference points to an invalid memory location.
We suggest that you only use this class in stable code where profiling has clearly identified that performance improvements can be made by replacing standard string operations with the optimized substring handling provided by this class.
See also .
Member Type Documentation
typedef QStringRef::const_iterator
This typedef provides an STL-style const iterator for .
This typedef was introduced in
See also .
typedef QStringRef::const_reverse_iterator
This typedef provides an STL-style const reverse iterator for .
This typedef was introduced in
See also .
Member Function Documentation
QStringRef::QStringRef()
Constructs an empty string reference.
QStringRef::QStringRef(const
*string, int position, int length)
Constructs a string reference to the range of characters in the given string specified by the starting position and length in characters.
Warning: This function exists to improve performance as much as possible, and performs no bounds checking. For program correctness, position and length must describe a valid substring of string.
This means that the starting position must be positive or 0 and smaller than string's length, and length must be positive or 0 but smaller than the string's length minus the starting position; i.e, 0 &= position & string-&() and 0 &= length &= string-&() - position must both be satisfied.
QStringRef::QStringRef(const
Constructs a string reference to the given string.
QStringRef::QStringRef(const
Constructs a copy of the other string reference.
QStringRef::QStringRef( &&other)
Move-copy constructor.
QStringRef::~QStringRef()
Destroys the string reference.
Since this class is only used to refer to string data, and does not take ownership of it, no memory is freed when instances are destroyed.
QStringRef::appendTo( *string) const
Appends the string reference to string, and returns a new reference to the combined string data.
QStringRef::at(int position) const
Returns the character at the given index position in the string reference.
The position must be a valid index position in the string (i.e., 0 &= position & ()).
QStringRef::begin() const
Returns a const
pointing to the first character in the string.
This function was introduced in
See also (), (), (), and ().
QStringRef::cbegin() const
Same as ().
This function was introduced in
See also (), (), (), and ().
QStringRef::cend() const
Same as ().
This function was introduced in
See also (), (), (), and ().
void QStringRef::clear()
Clears the contents of the string reference by making it null and empty.
See also () and ().
[static] int QStringRef::compare(const
&s1, const
cs = Qt::CaseSensitive)
Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
If cs is , the comparis otherwise the comparison is case insensitive.
This function was introduced in
int QStringRef::compare(const
cs = Qt::CaseSensitive) const
This is an overloaded function.
Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
If cs is , the comparis otherwise the comparison is case insensitive.
Equivalent to compare(*this, other, cs).
This function was introduced in
See also ().
int QStringRef::compare( other,
cs = Qt::CaseSensitive) const
This is an overloaded function.
Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
If cs is , the comparis otherwise the comparison is case insensitive.
Equivalent to compare(*this, other, cs).
This function was introduced in
See also ().
int QStringRef::compare(const
cs = Qt::CaseSensitive) const
This is an overloaded function.
Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
If cs is , the comparis otherwise the comparison is case insensitive.
Equivalent to compare(*this, other, cs).
This function was introduced in
See also ().
[static] int QStringRef::compare(const
&s1, const
cs = Qt::CaseSensitive)
This is an overloaded function.
Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
If cs is , the comparis otherwise the comparison is case insensitive.
This function was introduced in
[static] int QStringRef::compare(const
cs = Qt::CaseSensitive)
This is an overloaded function.
Compares the string s1 with the string s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
If cs is , the comparis otherwise the comparison is case insensitive.
This function was introduced in
*QStringRef::constData() const
Same as ().
bool QStringRef::contains(const
cs = Qt::CaseSensitive) const
Returns true if this string reference contains an occurrence of the string str; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::contains( ch,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns true if this string contains an occurrence of the character ch; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
bool QStringRef::contains( str,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns true if this string reference contains an occurrence of the string str; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::contains(const
cs = Qt::CaseSensitive) const
This function overloads ().
Returns true if this string reference contains an occurrence of the string reference str; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
int QStringRef::count() const
Returns the number of characters referred to by the string reference. Equivalent to () and ().
See also () and ().
int QStringRef::count(const
cs = Qt::CaseSensitive) const
Returns the number of (potentially overlapping) occurrences of the string str in this string reference.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), and ().
int QStringRef::count( ch,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the number of occurrences of the character ch in the string reference.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), and ().
int QStringRef::count(const
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the number of (potentially overlapping) occurrences of the string reference str in this string reference.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), and ().
QStringRef::crbegin() const
Same as ().
This function was introduced in
See also (), (), and ().
QStringRef::crend() const
Same as ().
This function was introduced in
See also (), (), and ().
*QStringRef::data() const
Same as ().
QStringRef::end() const
Returns a const
pointing to the imaginary character after the last character in the list.
This function was introduced in
See also (), end(), (), and ().
bool QStringRef::endsWith(const
cs = Qt::CaseSensitive) const
Returns true if the string reference ends with str; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::endsWith( str,
cs = Qt::CaseSensitive) const
This function overloads ().
This function was introduced in
See also () and ().
bool QStringRef::endsWith( ch,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns true if the string reference ends with ch; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::endsWith(const
cs = Qt::CaseSensitive) const
This function overloads ().
This function was introduced in
See also () and ().
int QStringRef::indexOf(const
&str, int from = 0,
cs = Qt::CaseSensitive) const
Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
If from is -1, the search starts a if it is -2, at the next to last character and so on.
This function was introduced in
See also (), (), (), and ().
int QStringRef::indexOf( ch, int from = 0,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the index position of the first occurrence of the character ch in the string reference, searching forward from index position from. Returns -1 if ch could not be found.
This function was introduced in
See also (), (), (), and ().
int QStringRef::indexOf( str, int from = 0,
cs = Qt::CaseSensitive) const
Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
If from is -1, the search starts a if it is -2, at the next to last character and so on.
This function was introduced in
See also (), (), (), and ().
int QStringRef::indexOf(const
&str, int from = 0,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the index position of the first occurrence of the string reference str in this string reference, searching forward from index position from. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), (), and ().
bool QStringRef::isEmpty() const
Returns true if the string referen otherwise returns false.
A string reference is empty if its size is zero.
See also ().
bool QStringRef::isNull() const
Returns true if () returns a null pointer or a poin otherwise returns true.
See also ().
int QStringRef::lastIndexOf(const
&str, int from = -1,
cs = Qt::CaseSensitive) const
Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from. If from is -1 (default), the search starts a if from is -2, at the next to last character and so on. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), (), and ().
int QStringRef::lastIndexOf( ch, int from = -1,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the index position of the last occurrence of the character ch, searching backward from position from.
This function was introduced in
See also (), (), (), and ().
int QStringRef::lastIndexOf( str, int from = -1,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from. If from is -1 (default), the search starts a if from is -2, at the next to last character and so on. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), (), and ().
int QStringRef::lastIndexOf(const
&str, int from = -1,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns the index position of the last occurrence of the string reference str in this string reference, searching backward from index position from. If from is -1 (default), the search starts a if from is -2, at the next to last character and so on. Returns -1 if str is not found.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also (), (), (), and ().
QStringRef::left(int n) const
Returns a substring reference to the n leftmost characters of the string.
If n is greater than or equal to (), or less than zero, a reference to the entire string is returned.
This function was introduced in
See also (), (), and ().
int QStringRef::length() const
Returns the number of characters referred to by the string reference. Equivalent to () and ().
See also () and ().
[static] int QStringRef::localeAwareCompare(const
&s1, const
Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
On macOS and iOS, this function compares according the "Order for sorted lists" setting in the International prefereces panel.
This function was introduced in
See also () and .
int QStringRef::localeAwareCompare(const
&other) const
This is an overloaded function.
Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
This function was introduced in
int QStringRef::localeAwareCompare(const
&other) const
This is an overloaded function.
Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
This function was introduced in
[static] int QStringRef::localeAwareCompare(const
&s1, const
This is an overloaded function.
Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
This function was introduced in
QStringRef::mid(int position, int n = -1) const
Returns a substring reference to n characters of this string, starting at the specified position.
If the position exceeds the length of the string, a null reference is returned.
If there are less than n characters available in the string, starting at the given position, or if n is -1 (default), the function returns all characters from the specified position onwards.
This function was introduced in
See also () and ().
int QStringRef::position() const
Returns the starting position in the referenced string that is referred to by the string reference.
See also () and ().
QStringRef::rbegin() const
Returns a const
reverse iterator pointing to the first character in the string, in reverse order.
This function was introduced in
See also (), (), and ().
QStringRef::rend() const
reverse iterator pointing to one past the last character in the string, in reverse order.
This function was introduced in
See also (), (), and ().
QStringRef::right(int n) const
Returns a substring reference to the n rightmost characters of the string.
If n is greater than or equal to (), or less than zero, a reference to the entire string is returned.
This function was introduced in
See also (), (), and ().
int QStringRef::size() const
Returns the number of characters referred to by the string reference. Equivalent to () and ().
See also () and ().
&& QStringRef::split(const
behavior = QString::KeepEmptyParts,
cs = Qt::CaseSensitive) const
Splits the string into substrings references wherever sep occurs, and returns the list of those strings. If sep does not match anywhere in the string, split() returns a single-element vector containing this string reference.
cs specifies whether sep should be matched case sensitively or case insensitively.
If behavior is , empty entries don't appear in the result. By default, empty entries are kept.
Note: All references are valid as long this string is alive. Destroying this string will cause all references be dangling pointers.This function was introduced in
&& QStringRef::split( sep,
behavior = QString::KeepEmptyParts,
cs = Qt::CaseSensitive) const
This is an overloaded function.
This function was introduced in
bool QStringRef::startsWith(const
cs = Qt::CaseSensitive) const
Returns true if the string reference starts with str; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::startsWith( str,
cs = Qt::CaseSensitive) const
This function overloads ().
This function was introduced in
See also () and ().
bool QStringRef::startsWith( ch,
cs = Qt::CaseSensitive) const
This function overloads ().
Returns true if the string reference starts with ch; otherwise returns false.
(default), the sear otherwise the search is case insensitive.
This function was introduced in
See also () and ().
bool QStringRef::startsWith(const
cs = Qt::CaseSensitive) const
This function overloads ().
This function was introduced in
See also () and ().
*QStringRef::string() const
Returns a pointer to the string referred to by the string reference, or 0 if it does not reference a string.
See also ().
double QStringRef::toDouble(bool *ok = Q_NULLPTR) const
Returns the string converted to a double value.
Returns 0.0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use ().
This function was introduced in
See also ().
float QStringRef::toFloat(bool *ok = Q_NULLPTR) const
Returns the string converted to a float value.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true. Returns 0.0 if the conversion fails.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
int QStringRef::toInt(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
QStringRef::toLatin1() const
Returns a Latin-1 representation of the string as a .
The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.
This function was introduced in
See also (), (), and .
QStringRef::toLocal8Bit() const
Returns the local 8-bit representation of the string as a . The returned byte array is undefined if the string contains characters not supported by the local 8-bit encoding.
() is used to perform the conversion from Unicode. If the locale encoding could not be determined, this function does the same as ().
If this string contains any characters that cannot be encoded in the locale, the returned byte array is undefined. Those characters may be suppressed or replaced by another.
This function was introduced in
See also (), (), and .
long QStringRef::toLong(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to a long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toLong()
This function was introduced in
See also ().
QStringRef::toLongLong(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to a long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
short QStringRef::toShort(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
QStringRef::toString() const
Returns a copy of the string reference as a
If the string reference is not a complete reference of the string (meaning that () is 0 and () equals ()-&()), this function will allocate a new string to return.
See also ().
QStringRef::toUInt(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
QStringRef::toULong(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to an unsigned long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
QStringRef::toULongLong(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to an unsigned long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
QStringRef::toUShort(bool *ok = Q_NULLPTR, int base = 10) const
Returns the string converted to an unsigned short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
If base is 0, the C language convention is used: If the string begins with "0x", base 16 if the string begins with "0", base 8 otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use ()
This function was introduced in
See also ().
&& QStringRef::toUcs4() const
Returns a UCS-4/UTF-32 representation of the string as a &uint&.
UCS-4 is a Unicode codec and therefore it is lossless. All characters from this string will be encoded in UCS-4. Any invalid sequence of code units in this string is replaced by the Unicode's replacement character (, which corresponds to U+FFFD).
The returned vector is not NUL terminated.
This function was introduced in
See also (), (), (), and .
QStringRef::toUtf8() const
Returns a UTF-8 representation of the string as a .
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like .
This function was introduced in
See also (), (), and .
QStringRef::trimmed() const
Returns a string that has whitespace removed from the start and the end.
Whitespace means any character for which () returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.
Unlike (), trimmed() leaves internal whitespace alone.
This function was introduced in
See also ().
void QStringRef::truncate(int position)
Truncates the string at the given position index.
If the specified position index is beyond the end of the string, nothing happens.
If position is negative, it is equivalent to passing zero.
This function was introduced in
See also ().
*QStringRef::unicode() const
Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not null-terminated unless the string reference includes the string's null terminator.
See also ().
bool QStringRef::operator!=(const char *s) const
This function overloads operator!=().
The s const char pointer is converted to a
using the fromUtf8() function.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is not lexically equal to the parameter string s. Otherwise returns false.
bool QStringRef::operator&(const char *s) const
This function overloads operator&().
The s const char pointer is converted to a
using the fromUtf8() function.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is lexically smaller than the parameter string s. Otherwise returns false.
bool QStringRef::operator&=(const char *s) const
This function overloads operator&=().
The s const char pointer is converted to a
using the fromUtf8() function.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is lexically smaller than or equal to the parameter string s. Otherwise returns false.
&QStringRef::operator=( &&other)
Move-assignment operator.
&QStringRef::operator=(const
Assigns the other string reference to this string reference, and returns the result.
&QStringRef::operator=(const
Constructs a string reference to the given string and assigns it to this string reference, returning the result.
bool QStringRef::operator==(const char *s) const
This function overloads operator==().
The s byte array is converted to a
using the fromUtf8() function. This function stops conversion at the first NUL character found, or the end of the byte array.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is lexically equal to the parameter string s. Otherwise returns false.
bool QStringRef::operator&(const char *s) const
This function overloads operator&().
The s const char pointer is converted to a
using the fromUtf8() function.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is lexically greater than the parameter string s. Otherwise returns false.
bool QStringRef::operator&=(const char *s) const
This function overloads operator&=().
The s const char pointer is converted to a
using the fromUtf8() function.
You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through (), for example.
Returns true if this string is lexically greater than or equal to the parameter string s. Otherwise returns false.
QStringRef::operator[](int position) const
Returns the character at the given index position in the string reference.
The position must be a valid index position in the string reference (i.e., 0 &= position & ()).
This function was introduced in
See also ().
Related Non-Members
bool operator&(const
&s1, const
Returns true if string reference s1 is lexically less than string reference s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the () function.
bool operator&=(const
&s1, const
Returns true if string reference s1 is lexically less than or equal to string reference s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the () function.
bool operator==(const
&s1, const
Returns true if string reference s1 is lexically equal to string reference s2; otherwise returns false.
bool operator==(const
&s1, const
Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.
bool operator==( s1, const
Returns true if string s1 is lexically equal to string reference s2; otherwise returns false.
bool operator&(const
&s1, const
Returns true if string reference s1 is lexically greater than string reference s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the () function.
bool operator&=(const
&s1, const
Returns true if string reference s1 is lexically greater than or equal to string reference s2; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the () function.
(C) 2016 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the
as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd.
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.

我要回帖

更多关于 bool 的文章

 

随机推荐