Macros | Functions | Variables
strings.c File Reference
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/strings.h"
#include "nvim/file_search.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/ops.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/eval/encode.h"

Macros

#define ESCAPE_COND(p, inquote, string_end)   (*p == '\\' && inquote && p + 1 < string_end && (p[1] == '\\' || p[1] == '"'))
 
#define OFF(attr)   offsetof(union typval_vval_union, attr)
 
#define TMP_LEN   350
 

Functions

char_uvim_strsave (const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 Copy "string" into newly allocated memory. More...
 
char_uvim_strnsave (const char_u *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
char_uvim_strsave_escaped (const char_u *string, const char_u *esc_chars) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
char_uvim_strsave_escaped_ext (const char_u *string, const char_u *esc_chars, char_u cc, bool bsl) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
char * vim_strnsave_unquoted (const char *const string, const size_t length) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
 
char_uvim_strsave_shellescape (const char_u *string, bool do_special, bool do_newline) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
char_uvim_strsave_up (const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
char_uvim_strnsave_up (const char_u *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
void vim_strup (char_u *p) FUNC_ATTR_NONNULL_ALL
 
char * strcase_save (const char *const orig, bool upper) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
void del_trailing_spaces (char_u *ptr) FUNC_ATTR_NONNULL_ALL
 
int vim_stricmp (const char *s1, const char *s2) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
 
int vim_strnicmp (const char *s1, const char *s2, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
 
char_uvim_strchr (const char_u *const string, const int c) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
void sort_strings (char_u **files, int count)
 
bool has_non_ascii (const char_u *s) FUNC_ATTR_PURE
 
bool has_non_ascii_len (const char *const s, const size_t len) FUNC_ATTR_PURE
 
char_uconcat_str (const char_u *restrict str1, const char_u *restrict str2) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
int vim_snprintf_add (char *str, size_t str_m, char *fmt,...) FUNC_ATTR_PRINTF(3
 
 if (str_m<=len)
 
 va_start (ap, fmt)
 
 va_end (ap)
 
int vim_snprintf (char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
 
int vim_vsnprintf (char *str, size_t str_m, const char *fmt, va_list ap, typval_T *const tvs)
 

Variables

int size_t space
 
 else
 
va_list ap
 
const int str_l = vim_vsnprintf(str + len, space, fmt, ap, NULL)
 

Macro Definition Documentation

#define ESCAPE_COND (   p,
  inquote,
  string_end 
)    (*p == '\\' && inquote && p + 1 < string_end && (p[1] == '\\' || p[1] == '"'))
#define OFF (   attr)    offsetof(union typval_vval_union, attr)
#define TMP_LEN   350

Function Documentation

char_u* concat_str ( const char_u *restrict  str1,
const char_u *restrict  str2 
)
void del_trailing_spaces ( char_u ptr)
bool has_non_ascii ( const char_u s)
bool has_non_ascii_len ( const char *const  s,
const size_t  len 
)

Return true if string "s" contains a non-ASCII character (128 or higher). When "s" is NULL false is returned.

if ( str_m<=  len)
void sort_strings ( char_u **  files,
int  count 
)
char* strcase_save ( const char *const  orig,
bool  upper 
)

Make given string all upper-case or all lower-case

Handles multi-byte characters as good as possible.

Parameters
[in]origInput string.
[in]upperIf true make uppercase, otherwise lowercase
Returns
[allocated] upper-cased string.
va_end ( ap  )
va_start ( ap  ,
fmt   
)
int vim_snprintf ( char *  str,
size_t  str_m,
const char *  fmt,
  ... 
)

Write formatted value to the string

Parameters
[out]strString to write to.
[in]str_mString length.
[in]fmtString format.
Returns
Number of bytes excluding NUL byte that would be written to the string if str_m was greater or equal to the return value.
int vim_snprintf_add ( char *  str,
size_t  str_m,
char *  fmt,
  ... 
)

Append a formatted value to the string

See also
vim_vsnprintf().
char_u* vim_strchr ( const char_u *const  string,
const int  c 
)

strchr() version which handles multibyte strings

Parameters
[in]stringString to search in.
[in]cCharacter to search for.
Returns
Pointer to the first byte of the found character in string or NULL if it was not found or character is invalid. NUL character is never found, use strlen() instead.
int vim_stricmp ( const char *  s1,
const char *  s2 
)
int vim_strnicmp ( const char *  s1,
const char *  s2,
size_t  len 
)
char_u* vim_strnsave ( const char_u string,
size_t  len 
)

Copy up to len bytes of string into newly allocated memory and terminate with a NUL. The allocated memory always has size len + 1, even when string is shorter.

char* vim_strnsave_unquoted ( const char *const  string,
const size_t  length 
)

Save a copy of an unquoted string

Turns string like a\bc"def\\"ghi\\\n"jkl</tt> into <tt>a\\bcdef"ghi\\njkl, for use in shell_build_argv: the only purpose of backslash is making next character be treated literally inside the double quotes, if this character is backslash or quote.

Parameters
[in]stringString to copy.
[in]lengthLength of the string to copy.
Returns
[allocated] Copy of the string.
char_u* vim_strnsave_up ( const char_u string,
size_t  len 
)
char_u* vim_strsave ( const char_u string)

Copy "string" into newly allocated memory.

char_u* vim_strsave_escaped ( const char_u string,
const char_u esc_chars 
)
char_u* vim_strsave_escaped_ext ( const char_u string,
const char_u esc_chars,
char_u  cc,
bool  bsl 
)
char_u* vim_strsave_shellescape ( const char_u string,
bool  do_special,
bool  do_newline 
)
char_u* vim_strsave_up ( const char_u string)
void vim_strup ( char_u p)
int vim_vsnprintf ( char *  str,
size_t  str_m,
const char *  fmt,
va_list  ap,
typval_T *const  tvs 
)

Write formatted value to the string

Parameters
[out]strString to write to.
[in]str_mString length.
[in]fmtString format.
[in]apValues that should be formatted. Ignored if tvs is not NULL.
[in]tvsValues that should be formatted, for printf() VimL function. Must be NULL in other cases.
Returns
Number of bytes excluding NUL byte that would be written to the string if str_m was greater or equal to the return value.

Variable Documentation

va_list ap
else
Initial value:
{
space = str_m - len
int len
Definition: helpers.c:1181
int size_t space
Definition: strings.c:689
int size_t space
Initial value:
{
const size_t len = strlen(str)
int len
Definition: helpers.c:1181
return str_l = vim_vsnprintf(str + len, space, fmt, ap, NULL)