converting to/from char[]/string

mark mark at qtrac.eu
Thu Mar 5 11:03:30 UTC 2020


I want to use the Porter stemming algorithm.
There's a D implementation here: 
https://tartarus.org/martin/PorterStemmer/d.txt

The main public function's signature is:

char[] stem(char[] p, int i, int j)

But I work entirely in terms of strings (containing individual 
words), so I want to add another function with this signature:

string stem(string word)

I've tried this without success:

     public string stem(string word) {
         import std.conv: to;

         char[] chars = word.to!char[];
         int end = chars.length.to!int;
         return stem(chars, 0, end).to!string;
     }

Here are just a few of the errors:

src/porterstemmer.d(197,13): Error: cannot implicitly convert 
expression s.length of type ulong to int
src/porterstemmer.d(222,9): Error: cannot implicitly convert 
expression cast(ulong)this.m_j + s.length of type ulong to int
src/porterstemmer.d(259,12): Error: function 
porterstemmer.PorterStemmer.ends(char[] s) is not callable using 
argument types (string)
src/porterstemmer.d(259,12):        cannot pass argument "sses" 
of type string to parameter char[] s



More information about the Digitalmars-d-learn mailing list