Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rolf Eike Beer
KWSys
Commits
043aa9d0
Commit
043aa9d0
authored
20 years ago
by
Sebastien Barre
Browse files
Options
Downloads
Patches
Plain Diff
ENH: move EstimateFormatLength to kwsys
parent
899b0133
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SystemTools.cxx
+69
-0
69 additions, 0 deletions
SystemTools.cxx
SystemTools.hxx.in
+12
-0
12 additions, 0 deletions
SystemTools.hxx.in
with
81 additions
and
0 deletions
SystemTools.cxx
+
69
−
0
View file @
043aa9d0
...
...
@@ -1096,6 +1096,75 @@ kwsys_stl::string SystemTools::CropString(const kwsys_stl::string& s,
return
n
;
}
//----------------------------------------------------------------------------
int
SystemTools
::
EstimateFormatLength
(
const
char
*
format
,
va_list
ap
)
{
if
(
!
format
)
{
return
0
;
}
// Quick-hack attempt at estimating the length of the string.
// Should never under-estimate.
// Start with the length of the format string itself.
int
length
=
strlen
(
format
);
// Increase the length for every argument in the format.
const
char
*
cur
=
format
;
while
(
*
cur
)
{
if
(
*
cur
++
==
'%'
)
{
// Skip "%%" since it doesn't correspond to a va_arg.
if
(
*
cur
!=
'%'
)
{
while
(
!
int
(
isalpha
(
*
cur
)))
{
++
cur
;
}
switch
(
*
cur
)
{
case
's'
:
{
// Check the length of the string.
char
*
s
=
va_arg
(
ap
,
char
*
);
if
(
s
)
{
length
+=
strlen
(
s
);
}
}
break
;
case
'e'
:
case
'f'
:
case
'g'
:
{
// Assume the argument contributes no more than 64 characters.
length
+=
64
;
// Eat the argument.
static_cast
<
void
>
(
va_arg
(
ap
,
double
));
}
break
;
default
:
{
// Assume the argument contributes no more than 64 characters.
length
+=
64
;
// Eat the argument.
static_cast
<
void
>
(
va_arg
(
ap
,
int
));
}
break
;
}
}
// Move past the characters just tested.
++
cur
;
}
}
return
length
;
}
// convert windows slashes to unix slashes
void
SystemTools
::
ConvertToUnixSlashes
(
kwsys_stl
::
string
&
path
)
{
...
...
This diff is collapsed.
Click to expand it.
SystemTools.hxx.in
+
12
−
0
View file @
043aa9d0
...
...
@@ -22,6 +22,7 @@
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <sys/types.h>
#include <stdarg.h>
#if defined( _MSC_VER )
typedef unsigned short mode_t;
...
...
@@ -188,6 +189,17 @@ public:
static char* AppendStrings(
const char* str1, const char* str2, const char* str3);
/**
* Estimate the length of the string that will be produced
* from printing the given format string and arguments. The
* returned length will always be at least as large as the string
* that will result from printing.
* WARNING: since va_arg is called to iterate of the argument list,
* you will not be able to use this 'ap' anymore from the beginning.
* It's up to you to call va_end though.
*/
static int EstimateFormatLength(const char *format, va_list ap);
/** -----------------------------------------------------------------
* Filename Manipulation Routines
* -----------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment