From 61d50bb6faca2b65483ee1eac6a214a5a1263a13 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 18 Jul 2021 14:20:06 -0700 Subject: [PATCH] str: New function ss_swap(). --- src/libpspp/str.c | 9 +++++++++ src/libpspp/str.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 99602fba68..86e7fd9199 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -425,6 +425,15 @@ ss_dealloc (struct substring *ss) free (ss->string); } +/* Exchanges the contents of A and B. */ +void +ss_swap (struct substring *a, struct substring *b) +{ + struct substring tmp = *a; + *a = *b; + *b = tmp; +} + /* Truncates SS to at most CNT bytes in length. */ void ss_truncate (struct substring *ss, size_t cnt) diff --git a/src/libpspp/str.h b/src/libpspp/str.h index 57783e0ea5..8cde577914 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -103,6 +103,7 @@ void ss_dealloc (struct substring *); /* Mutators. Functions that advance the beginning of a string should not be used if a substring is to be deallocated. */ +void ss_swap (struct substring *, struct substring *); void ss_truncate (struct substring *, size_t); size_t ss_rtrim (struct substring *, struct substring trim_set); size_t ss_ltrim (struct substring *, struct substring trim_set); -- 2.30.2