Let's admit it - sms length calculation is complicated. This is why we made an open-source SMS length calculator library.
You can download our free sms length calculator libraries from our github repository: https://github.com/messente/sms-length-calculator
It is just fresh out of the oven and may be rough around edges. Feel free to fork it, send us pull requests to make it better or even add new libraries for different languages.
Currently there are libraries for Java and PHP but we try to add more languages as we go.
Oh, and I did I say it was totally free? Check out quick summary for Apache Licence 2.0 just in case.
Don't forget that there is also an online version of SMS length calculator that you can check out on http://messente.com/documentation/sms-length-calculator