MCPcopy Create free account
hub / github.com/Kitware/CMake / EstimateFormatLength

Method EstimateFormatLength

Source/kwsys/SystemTools.cxx:1967–2023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1965}
1966
1967int SystemTools::EstimateFormatLength(char const* format, va_list ap)
1968{
1969 if (!format) {
1970 return 0;
1971 }
1972
1973 // Quick-hack attempt at estimating the length of the string.
1974 // Should never under-estimate.
1975
1976 // Start with the length of the format string itself.
1977
1978 size_t length = strlen(format);
1979
1980 // Increase the length for every argument in the format.
1981
1982 char const* cur = format;
1983 while (*cur) {
1984 if (*cur++ == '%') {
1985 // Skip "%%" since it doesn't correspond to a va_arg.
1986 if (*cur != '%') {
1987 while (!kwsysString_isalpha(*cur)) {
1988 ++cur;
1989 }
1990 switch (*cur) {
1991 case 's': {
1992 // Check the length of the string.
1993 char* s = va_arg(ap, char*);
1994 if (s) {
1995 length += strlen(s);
1996 }
1997 } break;
1998 case 'e':
1999 case 'f':
2000 case 'g': {
2001 // Assume the argument contributes no more than 64 characters.
2002 length += 64;
2003
2004 // Eat the argument.
2005 static_cast<void>(va_arg(ap, double));
2006 } break;
2007 default: {
2008 // Assume the argument contributes no more than 64 characters.
2009 length += 64;
2010
2011 // Eat the argument.
2012 static_cast<void>(va_arg(ap, int));
2013 } break;
2014 }
2015 }
2016
2017 // Move past the characters just tested.
2018 ++cur;
2019 }
2020 }
2021
2022 return static_cast<int>(length);
2023}
2024

Callers

nothing calls this directly

Calls 2

kwsysString_isalphaFunction · 0.85
strlenFunction · 0.50

Tested by

no test coverage detected