appendable.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (C) 2011-2012, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *******************************************************************************
  8. * file name: appendable.cpp
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2010dec07
  14. * created by: Markus W. Scherer
  15. */
  16. #include "unicode/utypes.h"
  17. #include "unicode/appendable.h"
  18. #include "unicode/utf16.h"
  19. U_NAMESPACE_BEGIN
  20. Appendable::~Appendable() {}
  21. UBool
  22. Appendable::appendCodePoint(UChar32 c) {
  23. if(c<=0xffff) {
  24. return appendCodeUnit((char16_t)c);
  25. } else {
  26. return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
  27. }
  28. }
  29. UBool
  30. Appendable::appendString(const char16_t *s, int32_t length) {
  31. if(length<0) {
  32. char16_t c;
  33. while((c=*s++)!=0) {
  34. if(!appendCodeUnit(c)) {
  35. return false;
  36. }
  37. }
  38. } else if(length>0) {
  39. const char16_t *limit=s+length;
  40. do {
  41. if(!appendCodeUnit(*s++)) {
  42. return false;
  43. }
  44. } while(s<limit);
  45. }
  46. return true;
  47. }
  48. UBool
  49. Appendable::reserveAppendCapacity(int32_t /*appendCapacity*/) {
  50. return true;
  51. }
  52. char16_t *
  53. Appendable::getAppendBuffer(int32_t minCapacity,
  54. int32_t /*desiredCapacityHint*/,
  55. char16_t *scratch, int32_t scratchCapacity,
  56. int32_t *resultCapacity) {
  57. if(minCapacity<1 || scratchCapacity<minCapacity) {
  58. *resultCapacity=0;
  59. return nullptr;
  60. }
  61. *resultCapacity=scratchCapacity;
  62. return scratch;
  63. }
  64. // UnicodeStringAppendable is implemented in unistr.cpp.
  65. U_NAMESPACE_END