//-----------------------------------------------------------------------------
// Copyright © 2005 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/string
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

__DEFINE_BEGIN__
//-----------------------------------------------------------------------------
// struct	strpl_s
// typedef	strpl_t, strpl_p
//
// purpose	Define a struct containing a string pointer and length.
//-----------------------------------------------------------------------------
struct strpl_s {
    char *	ptr				;
    size_t	len				;
};
typedef struct strpl_s		strpl_t		;
typedef struct strpl_s *	strpl_p		;

__DEFINE_END__

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	strpl
//
// purpose	Create a strpl value consisting of a string pointer and
//		length.
//
// arguments	1 (char *) string pointer
//		2 (size_t) string length
//
// note		This macro is "multiple evaluation safe".  All expressions
//		passed as arguments will only be evaluated once.
//-----------------------------------------------------------------------------
#define strpl(p,l) ({								\
	struct strpl_s libh__spl;						\
	libh__spl.ptr = (p);							\
	libh__spl.len = (l);							\
	libh__spl;								\
})

//-----------------------------------------------------------------------------
// macro	strpl_null
//
// purpose	Make a null value strpl.
//-----------------------------------------------------------------------------
#define strpl_null strpl((NULL),0)

//-----------------------------------------------------------------------------
// macro	strpl_ptr
//
// purpose	Extract the string pointer from a strpl value.
//-----------------------------------------------------------------------------
#define strpl_ptr(s) ((s).ptr)

//-----------------------------------------------------------------------------
// macro	strpl_len
//
// purpose	Extract the string length from a strpl value.
//-----------------------------------------------------------------------------
#define strpl_len(s) ((s).len)

//-----------------------------------------------------------------------------
// macro	strpl_end
//
// purpose	Extract the string end pointer from a strpl value.
//
// note		This macro is "multiple evaluation safe".  All expressions
//		passed as arguments will only be evaluated once.
//-----------------------------------------------------------------------------
#define strpl_end(s) ({								\
	struct strpl_s libh__spl;						\
	libh__spl = (s);							\
	libh__spl.len + libh__spl.ptr;						\
})

//-----------------------------------------------------------------------------
// macro	strpl_strpe
//
// purpose	Convert a strpl value to a strpe value.
//
// note		This macro is "multiple evaluation safe".  All expressions
//		passed as arguments will only be evaluated once.
//-----------------------------------------------------------------------------
#define strpl_strpe(s) ({							\
	struct strpl_s libh__strpl;						\
	struct strpe_s libh__strpe;						\
	libh__strpe.ptr = libh__strpl.ptr;					\
	libh__strpe.end = libh__strpl.len + libh__strpl.ptr;			\
	libh__strpe;								\
})

__FMACRO_END__

