How to truncate utf8 text

For example you have got some data from server in utf8 format and store it in some char(byte) array . Every symbol in text could be presented with different amount of bytes, here is example how to cut (restrict) it to desired lenght. Note: allocated clippedStr should be freed after usage...