Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KDevelop
KDevelop
Commits
048e144d
Commit
048e144d
authored
Oct 10, 2022
by
Igor Kushnir
Browse files
Remove unused language stringhelpers functions
parent
3abf44ee
Pipeline
#245955
passed with stage
in 32 minutes and 2 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
kdevplatform/language/duchain/stringhelpers.cpp
View file @
048e144d
...
...
@@ -11,69 +11,6 @@
#include
<QVarLengthArray>
namespace
{
template
<
typename
T
>
int
strip_impl
(
const
T
&
str
,
T
&
from
)
{
if
(
str
.
isEmpty
())
return
0
;
int
i
=
0
;
int
ip
=
0
;
int
s
=
from
.
length
();
for
(
int
a
=
0
;
a
<
s
;
a
++
)
{
if
(
QChar
::
fromLatin1
(
from
[
a
]).
isSpace
())
{
continue
;
}
else
{
if
(
from
[
a
]
==
str
[
i
])
{
i
++
;
ip
=
a
+
1
;
if
(
i
==
str
.
length
())
break
;
}
else
{
break
;
}
}
}
if
(
ip
)
{
from
.
remove
(
0
,
ip
);
}
return
s
-
from
.
length
();
}
template
<
typename
T
>
int
rStrip_impl
(
const
T
&
str
,
T
&
from
)
{
if
(
str
.
isEmpty
())
return
0
;
int
i
=
0
;
int
ip
=
from
.
length
();
int
s
=
from
.
length
();
for
(
int
a
=
s
-
1
;
a
>=
0
;
a
--
)
{
if
(
QChar
::
fromLatin1
(
from
[
a
])
.
isSpace
())
{
///@todo Check whether this can cause problems in utf-8, as only one real character is treated!
continue
;
}
else
{
if
(
from
[
a
]
==
str
[
i
])
{
i
++
;
ip
=
a
;
if
(
i
==
str
.
length
())
break
;
}
else
{
break
;
}
}
}
if
(
ip
!=
from
.
length
())
{
from
=
from
.
left
(
ip
);
}
return
s
-
from
.
length
();
}
bool
endsWithWordBoundary
(
QStringView
str
)
{
if
(
str
.
isEmpty
())
{
...
...
@@ -264,166 +201,6 @@ int findCommaOrEnd(const QString& str, int pos, QChar validEnd)
return
size
;
}
QString
reduceWhiteSpace
(
const
QString
&
str_
)
{
const
QStringRef
str
=
QStringRef
(
&
str_
).
trimmed
();
QString
ret
;
const
int
len
=
str
.
length
();
ret
.
reserve
(
len
);
bool
hadSpace
=
false
;
for
(
const
QChar
c
:
str
)
{
if
(
c
.
isSpace
())
{
hadSpace
=
true
;
}
else
{
if
(
hadSpace
)
{
hadSpace
=
false
;
ret
+=
QLatin1Char
(
' '
);
}
ret
+=
c
;
}
}
ret
.
squeeze
();
return
ret
;
}
void
fillString
(
QString
&
str
,
int
start
,
int
end
,
QChar
replacement
)
{
for
(
int
a
=
start
;
a
<
end
;
a
++
)
str
[
a
]
=
replacement
;
}
QString
stripFinalWhitespace
(
const
QString
&
str
)
{
for
(
int
a
=
str
.
length
()
-
1
;
a
>=
0
;
--
a
)
{
if
(
!
str
[
a
].
isSpace
())
return
str
.
left
(
a
+
1
);
}
return
QString
();
}
QString
clearComments
(
const
QString
&
str_
,
QChar
replacement
)
{
QString
str
(
str_
);
QString
withoutStrings
=
clearStrings
(
str
,
QLatin1Char
(
'$'
));
int
pos
=
-
1
,
newlinePos
=
-
1
,
endCommentPos
=
-
1
,
nextPos
=
-
1
,
dest
=
-
1
;
while
((
pos
=
str
.
indexOf
(
QLatin1Char
(
'/'
),
pos
+
1
))
!=
-
1
)
{
newlinePos
=
withoutStrings
.
indexOf
(
QLatin1Char
(
'\n'
),
pos
);
if
(
withoutStrings
[
pos
+
1
]
==
QLatin1Char
(
'/'
))
{
//C style comment
dest
=
newlinePos
==
-
1
?
str
.
length
()
:
newlinePos
;
fillString
(
str
,
pos
,
dest
,
replacement
);
pos
=
dest
;
}
else
if
(
withoutStrings
[
pos
+
1
]
==
QLatin1Char
(
'*'
))
{
//CPP style comment
endCommentPos
=
withoutStrings
.
indexOf
(
QLatin1String
(
"*/"
),
pos
+
2
);
if
(
endCommentPos
!=
-
1
)
endCommentPos
+=
2
;
dest
=
endCommentPos
==
-
1
?
str
.
length
()
:
endCommentPos
;
while
(
pos
<
dest
)
{
nextPos
=
(
dest
>
newlinePos
&&
newlinePos
!=
-
1
)
?
newlinePos
:
dest
;
fillString
(
str
,
pos
,
nextPos
,
replacement
);
pos
=
nextPos
;
if
(
pos
==
newlinePos
)
{
++
pos
;
//Keep newlines intact, skip them
newlinePos
=
withoutStrings
.
indexOf
(
QLatin1Char
(
'\n'
),
pos
+
1
);
}
}
}
}
return
str
;
}
QString
clearStrings
(
const
QString
&
str_
,
QChar
replacement
)
{
QString
str
(
str_
);
bool
inString
=
false
;
for
(
int
pos
=
0
;
pos
<
str
.
length
();
++
pos
)
{
//Skip cpp comments
if
(
!
inString
&&
pos
+
1
<
str
.
length
()
&&
str
[
pos
]
==
QLatin1Char
(
'/'
)
&&
str
[
pos
+
1
]
==
QLatin1Char
(
'*'
))
{
pos
+=
2
;
while
(
pos
+
1
<
str
.
length
())
{
if
(
str
[
pos
]
==
QLatin1Char
(
'*'
)
&&
str
[
pos
+
1
]
==
QLatin1Char
(
'/'
))
{
++
pos
;
break
;
}
++
pos
;
}
}
//Skip cstyle comments
if
(
!
inString
&&
pos
+
1
<
str
.
length
()
&&
str
[
pos
]
==
QLatin1Char
(
'/'
)
&&
str
[
pos
+
1
]
==
QLatin1Char
(
'/'
))
{
pos
+=
2
;
while
(
pos
<
str
.
length
()
&&
str
[
pos
]
!=
QLatin1Char
(
'\n'
))
{
++
pos
;
}
}
//Skip a character a la 'b'
if
(
!
inString
&&
str
[
pos
]
==
QLatin1Char
(
'\''
)
&&
pos
+
3
<=
str
.
length
())
{
//skip the opening '
str
[
pos
]
=
replacement
;
++
pos
;
if
(
str
[
pos
]
==
QLatin1Char
(
'\\'
))
{
//Skip an escape character
str
[
pos
]
=
replacement
;
++
pos
;
}
//Skip the actual character
str
[
pos
]
=
replacement
;
++
pos
;
//Skip the closing '
if
(
pos
<
str
.
length
()
&&
str
[
pos
]
==
QLatin1Char
(
'\''
))
{
str
[
pos
]
=
replacement
;
}
continue
;
}
bool
intoString
=
false
;
if
(
str
[
pos
]
==
QLatin1Char
(
'"'
)
&&
!
inString
)
intoString
=
true
;
if
(
inString
||
intoString
)
{
if
(
inString
)
{
if
(
str
[
pos
]
==
QLatin1Char
(
'"'
))
inString
=
false
;
}
else
{
inString
=
true
;
}
bool
skip
=
false
;
if
(
str
[
pos
]
==
QLatin1Char
(
'\\'
))
skip
=
true
;
str
[
pos
]
=
replacement
;
if
(
skip
)
{
++
pos
;
if
(
pos
<
str
.
length
())
str
[
pos
]
=
replacement
;
}
}
}
return
str
;
}
int
strip
(
const
QByteArray
&
str
,
QByteArray
&
from
)
{
return
strip_impl
<
QByteArray
>
(
str
,
from
);
}
int
rStrip
(
const
QByteArray
&
str
,
QByteArray
&
from
)
{
return
rStrip_impl
<
QByteArray
>
(
str
,
from
);
}
// NOTE: keep in sync with QString overload below
QByteArray
formatComment
(
const
QByteArray
&
comment
)
{
...
...
kdevplatform/language/duchain/stringhelpers.h
View file @
048e144d
...
...
@@ -33,24 +33,6 @@ int KDEVPLATFORMLANGUAGE_EXPORT findClose(const QString& str, int pos);
*/
int
KDEVPLATFORMLANGUAGE_EXPORT
findCommaOrEnd
(
const
QString
&
str
,
int
pos
,
QChar
validEnd
=
QLatin1Char
(
' '
));
/**
* Removes white space at the beginning and end, and replaces contiguous inner white-spaces with single white-spaces. Newlines are treated as whitespaces, the returned text will have no more newlines.
*/
QString
KDEVPLATFORMLANGUAGE_EXPORT
reduceWhiteSpace
(
const
QString
&
str
);
QString
KDEVPLATFORMLANGUAGE_EXPORT
stripFinalWhitespace
(
const
QString
&
str
);
//
/**
* Fills all c++-style comments within the given code with the given 'replacement' character
* Newlines are preserved.
*/
QString
KDEVPLATFORMLANGUAGE_EXPORT
clearComments
(
const
QString
&
str
,
QChar
replacement
=
QLatin1Char
(
' '
));
/**
* Fills all c++-strings within the given code with the given 'replacement' character
* Comments should have been removed before.
*/
QString
KDEVPLATFORMLANGUAGE_EXPORT
clearStrings
(
const
QString
&
str
,
QChar
replacement
=
QLatin1Char
(
' '
));
/**
* Extracts the interesting information out of a comment.
* For example it removes all the stars at the beginning, and re-indents the text.
...
...
@@ -63,20 +45,6 @@ QString KDEVPLATFORMLANGUAGE_EXPORT formatComment(const QString& comment);
*/
QByteArray
KDEVPLATFORMLANGUAGE_EXPORT
formatComment
(
const
QByteArray
&
comment
);
/**
* Remove characters in @p str from the end of @p from
*
* @return number of stripped characters
*/
int
KDEVPLATFORMLANGUAGE_EXPORT
rStrip
(
const
QByteArray
&
str
,
QByteArray
&
from
);
/**
* Remove characters in @p str from the beginning of @p from
*
* @return number of stripped characters
*/
int
KDEVPLATFORMLANGUAGE_EXPORT
strip
(
const
QByteArray
&
str
,
QByteArray
&
from
);
/**
* Removes all whitespace from the string
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment