


//
// String?
//

[A]
String?(static A) = false;

[A | Sequence?(A) and (Char == SequenceElementType(A))]
overload String?(static A) = true;



//
// SizedString?
//

[A]
SizedString?(static A) = false;

[A | SizedSequence?(A) and (Char == SequenceElementType(A))]
overload SizedString?(static A) = true;



//
// ContiguousString?
//

[A]
ContiguousString?(static A) = false;

[A | ContiguousSequence?(A) and (Char == SequenceElementType(A))]
overload ContiguousString?(static A) = true;



//
// CCompatibleString?
//

[A]
CCompatibleString?(static A) = false;

[A | String?(A) and CallDefined?(cstring, A)]
overload CCompatibleString?(static A) = true;



//
// String
//

alias String = Vector[Char];



//
// construct from sequences of bytes
//

[A | Sequence?(A) and ByteSizedInteger?(SequenceElementType(A))]
inline overload String(a:A) = String(mapped(Char, a));



//
// construct from c-string
//

[T | ByteSizedInteger?(T)]
inline overload String(cstr : Pointer[T]) = String(CStringRef(cstr));



//
// convert to c-compatible string
//

cstring(s:String) {
    reserve(s, size(s)+1);
    end(s)^ = Char(0);
    return Pointer[Int8](s.data);
}
