<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139028>139028</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-c/Feature Request] add clang_getCString_length
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
illusory0x0
</td>
</tr>
</table>
<pre>
If CXString::data point to [std::string_view](https://en.cppreference.com/w/cpp/string/basic_string_view), then we needn't use `strlen` to count length.
```c++
unsigned clang_getCString_length(CXString string) {
if (string.private_flags == (unsigned) CXS_StringBuf) {
return static_cast<const cxstring::CXStringBuf *>(string.data)->Data.size();
}
return strlen(static_cast<const char *>(string.data));
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0U81uqzoQfpphYwU5dkxgwSI_Rbrb2013kTET8BU1XHuctOfpjwxN2yOdSiONxPD9zPChQ7C9Q6xBHUGdMx1pmHxtxzGGyb_zN561U_de_3Nlp5dn8tb1IA8gD50mzebJOmI0MVDHQN06Cctbl5vFO6gziHIgmkOaiQZEgy438-zxih6dwdxMryCaO4jGzDOIZoWDaFodrLl8ZxMViBOjAR27I3OInQOxJxYDMih4ID-ig4InR2aKjtiIrqchB35IVfC1DIhjKn6Iblm_Y2bUrr_0SKd1ycuKBFE-1mYPYxWDfcIyZq8MRLk-z2dvb5rwch11HxjIM8hzGj8kEvD08nxZ2Y7x-p2JMY8UvWOBNFlzMToQyJOZXCBm3sK3wz_8HGNSP4B8-vKQPgqIagPy6axJ58H-QhBlOpxchWB_Xvqn3HKyRPAX3UH7nyQ-KVfCz9NmXS27SlY6w3q73xVFKYu9yoZaIe7VVlWF6tpyp4tqp0ttVMuxaivJq8zWggvFFS-5UjupciW1rLiWe7HlpjJX2HF81XbMx_H2mk--z2wIEeutrLgos1G3OIYlx0I4vLNlCkKkWPs6gTZt7APs-GgDhS8asjQuP8ASgo0B0TSoKXpk_-L_EQOBOjPd_ZiSLPqx_jPlvaUhth_hTkofbTP76T80BKJZ_AUQzccCt1r8DgAA__893x7p">