message_segment_calculator 1.3.0
message_segment_calculator: ^1.3.0 copied to clipboard
Efficiently calculate SMS segments for messages with support for GSM and UCS-2 encoding. Ideal for apps that require precise SMS length and cost management.
1.3.0 #
Brings the package in line with Twilio's official calculator (TwilioDevEd/message-segment-calculator v1.3.0). Verified by running both calculators on more than 10,000 messages (emoji, flags, skin tones, ZWJ sequences, accents, CJK, GSM-7 extension characters, line breaks, smart encoding, forced encodings) and comparing every output; they agree on all of them.
Fixed #
- Grapheme splitting now matches Twilio β Replaced
package:characterswith a Dart port of grapheme-splitter 1.0.4, the splitter Twilio uses. Newer emoji sequences (e.g. π΄ββ οΈ, π«±πΌβπ«²πΏ, π¦βπ₯) are split the same way, so the character and segment counts are the same as Twilio's. - Spaces and line breaks were reported as non-GSM β
EncodedChar.isGSM7trimmed the character before checking it, so' ','\n'and'\r'werefalseand showed up ingetNonGsmCharacters(). - GSM extension characters in UCS-2 messages β
|,^,{,β¬, β¦ now keep their single UTF-16 code unit incodeUnitswhen the message is UCS-2, instead of the 2-unit GSM-7 escape sequence (Twilio #57/#61). - Line break style β A message with only CRLF line breaks is now reported
as
LineBreakStyle.crlfinstead oflfCrlf(Twilio #67). - Smart encoding β
βΉandβΊnow map to<and>(they were swapped, Twilio #58), and ZERO WIDTH NON-JOINER (U+200C) is removed. Smart encoding now iterates Unicode code points, like Twilio. - Line break warning now uses Twilio's exact wording.
Segment.addHeader()setshasUserDataHeadertofalselike Twilio (hasTwilioReservedBitsistrue). Segment counts are unaffected.
Added #
RcsSegmentedMessageβ RCS billing (UTF-8 bytes): US messages are split into 160-byte "Rich" segments; international messages are "Basic" (β€160 bytes) or "Single" (>160 bytes, capacity 1600).countUtf8Bytes()β UTF-8 byte length of a message.- Port of Twilio's full test suite (
test/twilio_parity_test.dart).
Changed #
- The package no longer depends on
package:characters.
1.2.0 #
Added #
remainingCharsInSegmentproperty β Returns how many characters can still be added to the current (last) segment before a new segment is created. Useful for building real-time character counters and SMS cost previews.maxCharsPerSegmentproperty β Returns the maximum number of characters that fit in a single segment for the current encoding. Accounts for the User Data Header overhead in multi-segment messages (GSM-7: 160β153, UCS-2: 70β67).- 8 new unit tests β Comprehensive tests covering empty messages, exact boundary, single/multi-segment transitions, and extended GSM-7 characters for both new properties.
1.1.2 #
Fixed #
- CI/CD: skip example directory during publish β The
example/folder is a Flutter project which causeddart pub getto fail with exit code 69. CI now uses--no-examplefor dependency resolution and scopes format/analyze tolib/andtest/only.
1.1.1 #
Fixed #
- Replaced
flutter_lintswithlintsβ Theflutter_lintsdev dependency pulled in the Flutter SDK, causingdart pub publishto fail on CI with exit code 69. Replaced with the pure Dartlintspackage.
1.1.0 #
Breaking Changes #
- Converted to a pure Dart package β Removed Flutter SDK dependency (
flutter,flutter_test), making the package usable in any Dart project (CLI, server-side, Flutter, etc.). - Renamed
SmsEncodingenum toSmsEncodingModeβ The previousSmsEncodingenum (withgsm7,ucs2,auto) is nowSmsEncodingMode. A newSmsEncodingenum (withgsm7,ucs2only) represents the resolved encoding. - Removed
ValidEncodingValuesenum β Replaced by the newSmsEncodingenum. - Replaced string-based encoding with enums β
EncodedCharnow usesSmsEncodingenum instead of raw strings like'gsm7'/'ucs2'.
Added #
- Introduced
SegmentElementsealed class β A new base type forEncodedCharandUserDataHeader, enabling type-safe segment composition and proper polymorphism. - Added new test cases β Tests for long GSM-7 multi-segment messages and long UCS-2 multi-segment messages.
- Added
toString()override onSegmentβ Useful for debugging segment details. - Added
repository,issue_tracker, andtopicsmetadata topubspec.yamlfor better pub.flutter-io.cn discoverability.
Changed #
- Replaced
grapheme_splitterdependency withcharactersβ Uses the official Dartcharacterspackage for grapheme splitting, reducing dependency bloat. - Replaced
flutter_testwithtestpackage β Tests now use the standard Darttestpackage. - Type-safe segment elements β
Segment._elementschanged fromList<dynamic>toList<SegmentElement>,add()andremoveLast()now useSegmentElementtype. - Simplified line break processing β Grapheme line break handling now uses
expand()instead offold(). - Simplified
_hasAnyUCSCharactersβ Refactored from a verbose loop to a conciseany()expression. - Improved
sizeInBits()calculations βSegment.sizeInBits()now correctly sums all element sizes (previously ignoredUserDataHeadersizes in computation). - Fixed
addHeader()bug βhasUserDataHeaderis now correctly set totrue(was previously set tofalseby mistake). - Fixed typo in filename β Renamed
enchoded_char.darttoencoded_char.dart. - Code cleanup β Replaced
var/explicit types withfinalwhere appropriate, used expression body syntax, and improved formatting throughout.
Removed #
- Removed
grapheme_splitterdependency β Replaced by thecharacterspackage. - Removed Flutter SDK dependency β Package is now pure Dart.
1.0.9 #
Changed #
- fix : removed unused functions
- fix : removed unused variables
- fix : removed unused imports
- fix : Code format and refractor
1.0.8 #
Changed #
- fix : segment calculation logics
- improved usability
- fix : encoding logic
- Updated the README with detailed descriptions and usage examples.
0.0.7 #
Added #
- Added the
SegmentedMessageclass to handle the segmentation logic for dividing a message into multiple SMS segments. - Added the
EncodedCharclass to represent individual characters and their encoding properties. - Added the
Segmentclass to manage individual segments, handle additions and removals, and calculate segment sizes. - Added the
UserDataHeaderclass to represent the User Data Header required for concatenated SMS messages. - Enabled
public_member_api_docslint to ensure all public API members are documented. - Introduced example usage in README for easy integration.
Changed #
- Improved error handling in the main entry point for better debugging and usability.
- Updated the README with detailed descriptions and usage examples.
0.0.1 #
- TODO: Describe initial release.