Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniCompressor.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser.
  6. ** It may not be distributed under any circumstances.
  7. */
  8. #ifndef UNICOMPRESSOR_H
  9. #define UNICOMPRESSOR_H
  10. #include "modules/search_engine/TypeDescriptor.h" // For the CHECK_RESULT macro
  11. /**
  12. * @brief Very fast algorithm to compress and decompress unicode text.
  13. * @author Pavel Studeny <pavels@opera.com>
  14. *
  15. * The compression/decompression speed is similar to the world's fastest compression, LZO.
  16. */
  17. class UniCompressor : public NonCopyable
  18. {
  19. public:
  20. UniCompressor(void) {m_dict = NULL;}
  21. ~UniCompressor(void) {FreeCompDict();}
  22. /**
  23. * init internal ditionary, only needed for compression
  24. */
  25. CHECK_RESULT(OP_STATUS InitCompDict(void));
  26. /**
  27. * free internal dictionary
  28. */
  29. void FreeCompDict(void) {if (m_dict != NULL) OP_DELETEA(m_dict); m_dict = NULL;}
  30. /**
  31. * compress a block of unicode text
  32. * @param dst 3 * uni_strlen(src) * sizeof(uni_char) / 2 + 6 B must be available
  33. * @param src unicode text ended by 0
  34. * @return length of output data stored in dst
  35. */
  36. unsigned Compress(unsigned char *dst, const uni_char *src);
  37. /**
  38. * length of original data should be kept to allocate a sufficient buffer for decompression
  39. * @param dst buffer for original text, text is terminated by 0
  40. * @param src compressed data
  41. * @param len length of src
  42. * @return length of uncompressed text without the terminating 0
  43. */
  44. unsigned Decompress(uni_char *dst, const unsigned char *src, unsigned len);
  45. /**
  46. * @return the original length of the compressed data excluding the terminating 0
  47. */
  48. unsigned Length(const unsigned char *src);
  49. protected:
  50. inline unsigned char *OutputLiteral(unsigned char *op, const uni_char *sp, const uni_char *cp);
  51. inline unsigned char *OutputMatch(unsigned char *op, unsigned length, unsigned short offset);
  52. UINT32 *m_dict;
  53. };
  54. #endif // UNICOMPRESSOR_H