Skip to content

Commit

Permalink
refactor: Use enum-from-int rule from tokstyle.
Browse files Browse the repository at this point in the history
These functions are a bit clearer and don't need to change if enum
values change.

See TokTok/hs-tokstyle#212 for the relevant
linter implementation.
  • Loading branch information
iphydf committed Dec 18, 2023
1 parent 90f7496 commit 49ee322
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
849ec5686eeaea448f4ef99650b016c883e6ea13d5fa2e7b2a344c9275a10431 /usr/local/bin/tox-bootstrapd
603c0892e737eb7b2bb6e6a7ba6407a847c90dad34ab1e3919f5259069c35540 /usr/local/bin/tox-bootstrapd
8 changes: 5 additions & 3 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,14 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
static Userstatus userstatus_from_int(uint8_t status)
{
switch (status) {
case 0:
case USERSTATUS_NONE:
return USERSTATUS_NONE;
case 1:
case USERSTATUS_AWAY:
return USERSTATUS_AWAY;
case 2:
case USERSTATUS_BUSY:
return USERSTATUS_BUSY;
case USERSTATUS_INVALID:
return USERSTATUS_INVALID;

Check warning on line 770 in toxcore/Messenger.c

View check run for this annotation

Codecov / codecov/patch

toxcore/Messenger.c#L770

Added line #L770 was not covered by tests
default:
return USERSTATUS_INVALID;
}
Expand Down
10 changes: 5 additions & 5 deletions toxcore/group_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
Group_Privacy_State group_privacy_state_from_int(uint8_t value)
{
switch (value) {
case 0:
case GI_PUBLIC:
return GI_PUBLIC;
case 1:
case GI_PRIVATE:
return GI_PRIVATE;
default:
return GI_PUBLIC;
Expand All @@ -33,11 +33,11 @@ Group_Privacy_State group_privacy_state_from_int(uint8_t value)
Group_Voice_State group_voice_state_from_int(uint8_t value)
{
switch (value) {
case 0:
case GV_ALL:
return GV_ALL;
case 1:
case GV_MODS:
return GV_MODS;
case 2:
case GV_FOUNDER:
return GV_FOUNDER;
default:
return GV_ALL;
Expand Down
26 changes: 13 additions & 13 deletions toxcore/tox_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
static Tox_Conference_Type tox_conference_type_from_int(uint32_t value)
{
switch (value) {
case 0:
case TOX_CONFERENCE_TYPE_TEXT:
return TOX_CONFERENCE_TYPE_TEXT;
case 1:
case TOX_CONFERENCE_TYPE_AV:
return TOX_CONFERENCE_TYPE_AV;
default:
return TOX_CONFERENCE_TYPE_TEXT;
Expand All @@ -35,11 +35,11 @@ bool tox_unpack_conference_type(Bin_Unpack *bu, Tox_Conference_Type *val)
static Tox_Connection tox_connection_from_int(uint32_t value)
{
switch (value) {
case 0:
case TOX_CONNECTION_NONE:
return TOX_CONNECTION_NONE;
case 1:
case TOX_CONNECTION_TCP:
return TOX_CONNECTION_TCP;
case 2:
case TOX_CONNECTION_UDP:
return TOX_CONNECTION_UDP;
default:
return TOX_CONNECTION_NONE;
Expand All @@ -60,11 +60,11 @@ bool tox_unpack_connection(Bin_Unpack *bu, Tox_Connection *val)
static Tox_File_Control tox_file_control_from_int(uint32_t value)
{
switch (value) {
case 0:
case TOX_FILE_CONTROL_RESUME:
return TOX_FILE_CONTROL_RESUME;
case 1:
case TOX_FILE_CONTROL_PAUSE:
return TOX_FILE_CONTROL_PAUSE;
case 2:
case TOX_FILE_CONTROL_CANCEL:
return TOX_FILE_CONTROL_CANCEL;
default:
return TOX_FILE_CONTROL_RESUME;
Expand All @@ -85,9 +85,9 @@ bool tox_unpack_file_control(Bin_Unpack *bu, Tox_File_Control *val)
static Tox_Message_Type tox_message_type_from_int(uint32_t value)
{
switch (value) {
case 0:
case TOX_MESSAGE_TYPE_NORMAL:
return TOX_MESSAGE_TYPE_NORMAL;
case 1:
case TOX_MESSAGE_TYPE_ACTION:
return TOX_MESSAGE_TYPE_ACTION;
default:
return TOX_MESSAGE_TYPE_NORMAL;
Expand All @@ -108,11 +108,11 @@ bool tox_unpack_message_type(Bin_Unpack *bu, Tox_Message_Type *val)
static Tox_User_Status tox_user_status_from_int(uint32_t value)
{
switch (value) {
case 0:
case TOX_USER_STATUS_NONE:
return TOX_USER_STATUS_NONE;
case 1:
case TOX_USER_STATUS_AWAY:
return TOX_USER_STATUS_AWAY;
case 2:
case TOX_USER_STATUS_BUSY:
return TOX_USER_STATUS_BUSY;
default:
return TOX_USER_STATUS_NONE;
Expand Down

0 comments on commit 49ee322

Please sign in to comment.