GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - submada/basic-string: String for dlang

BranchesTags
Open more actions menu

Latest commit

 

History

71 Commits
71 Commits

Folders and files

NameName
Last commit message
Last commit date
src/basic_string
src/basic_string
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
dub.json
dub.json
 
 

Repository files navigation

BasicString

Content of basic-string repository was moved to BTL repository as subpackage btl:string

Documentation

https://submada.github.io/btl/btl/string.html

C++-style string for D using std.experimental.allocator.

The BasicString is the generalization of struct string for character type char, wchar and dchar.

Features

Allocator is template argument instead of using theAllocator so that string can be used in @nogc code. Default allocator is Mallocator.

BasicString use Small String Optimization (SSO)

Works with pure, @safe, @nogc and nothrow.

Compatible with -betterC

-dip1000 is too unstable, for now is not supported.

Does not rely on runtime type information (TypeInfo).

Example

pure nothrow @safe @nogc unittest {
  import std.experimental.allocator.mallocator : Mallocator;

  alias String = BasicString!(
    char,               //character type
    Mallocator,         //allocator type (can be stateless or with state)
    32                  //additional padding to increas max size of small string (small string does not allocate memory).
  );

  //copy:
  {
    String a = "123";
    String b = a;
    
    a = "456"d;
    
    assert(a == "456");
    assert(b == "123");
  }
  
  
  //append:
  {
    String str = "12";

    str.append("34");   //same as str += "34"
    str.append("56"w);  //same as str += "56"w
    str.append(7);      //same as str += 7;
    str.append('8');

    assert(str == "12345678");

    str.clear();

    assert(str.empty);

  }

  //erase:
  {
    String str = "123456789";

    str.erase(2, 2);

    assert(str == "1256789");
  }

  //insert:
  {
    String str = "123456789";

    str.insert(1, "xyz");

    assert(str == "1xyz23456789");
  }

  //replace:
  {
    String str = "123456789";

    str.replace(1, 2, "xyz");

    assert(str == "1xyz456789");
  }

  //slice to string:
  ()@trusted{
    String str = "123456789";

    string dstr = str[];

    assert(str == dstr);
  }();
}

About

String for dlang

Topics

allocatorsdlangnogcnothrowpurestring

Resources

Readme
BSL-1.0 license
Activity

Stars

5 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.